site_url & base_url performance |
hey,
while optimizing my application I noticed that site_url & base_url are very slow. So caching the base_url improved my menu generation speed by 95%. All tests with 100 request & 24 calls
It's always slow on the first try because the page has not been cached yet!
Second time around you will get a faster load speed. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
06-12-2018, 04:59 AM
(This post was last modified: 06-12-2018, 05:31 AM by puschie. Edit Reason: add test results )
yes, but not everything can be cached, so it would be very practical if you could use the URL functions very often ( personally I also find it much better readable ).
i am not very familiar with all the scenarios that site_url is about, so it would be nice if someone could give some detailed information about the extent to which site_url can be optimized. about 1ms execution time for a single site_url call is a way too slow and not acceptable. Edit: the slowest part is url_helper.php:58 -> creating a new config | cost about 0.65ms the constructor of BaseConfig needs about 0.6ms for creating a new Config/App instance -> do we need a clean instance on every call ? maybe we should use a shared instance as default and create a new one on null passed as third parameter
That is why I prefer to use a constant.
constants.php PHP Code: define('BASE_URL', 'http://yourdomain.com/codeigniter/'); and config.php PHP Code: $config['base_url'] = BASE_URL; In the views: Code: <a href="<?php echo BASE_URL."controller/method" ?> >Action</a>
Good catch. We would definitely be interested in a pull request for that!
06-13-2018, 04:06 AM
(This post was last modified: 06-14-2018, 07:37 AM by puschie. Edit Reason: add new links ) |
Welcome Guest, Not a member yet? Register Sign In |