site_url & base_url performance - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31) +--- Thread: site_url & base_url performance (/showthread.php?tid=70870) |
site_url & base_url performance - puschie - 06-11-2018 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
RE: site_url & base_url performance - InsiteFX - 06-12-2018 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. RE: site_url & base_url performance - puschie - 06-12-2018 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 RE: site_url & base_url performance - davicotico - 06-12-2018 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> RE: site_url & base_url performance - kilishan - 06-12-2018 Good catch. We would definitely be interested in a pull request for that! RE: site_url & base_url performance - puschie - 06-13-2018 Pull Request New PR Issue |