• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
site_url & base_url performance

#1
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
  • site_url( $URI ) : 21ms
  • site_url().$URI : 20ms
  • base_url( $URI ) : 8.8ms
  • base_url().$URI : 3.5ms
  • single base_url() call : 0.2ms
  • single site_url() call : 1.0ms
So maybe we can add an cache mechanic to these functions ?
Reply

#2
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 )
Reply

#3
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
Reply

#4
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>

Reply

#5
Good catch. We would definitely be interested in a pull request for that!
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply

#6
Pull Request

New PR

Issue
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.