Part of the EllisLab Network
   
8 of 8
8
Making CodeIgniter faster, one line at a time
Posted: 08 May 2007 08:39 AM   [ Ignore ]   [ # 106 ]  
Summer Student
Avatar
Total Posts:  10
Joined  01-13-2007

I just had some time so I looked at the code some more… How about “caching” some values in different functions… for example:

In Config.php you can find the following function

function system_url()
{
    $x
= explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
    return
$this->slash_item('base_url').end($x).'/';
}

by replacing it with something like

function system_url()
{
    
static $system;
            
    if (!isset(
$system))
    
{
        $x
= explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
        
$system = $this->slash_item('base_url').end($x).'/';
        return
$system;
    
}
    
else
        return
$system;
}

we only have to execute the RegEx once… (of course it would be better to remove the RegEx if possible, but using static vars (or the $_GLOBALS array) to store some values could be an option if we can’t remove the RegEx easily and if the value doesn’t change during the execution of CI)

 Signature 

Btw. my Username is my real name… It has absolutly nothing to do with religion or stuff like that tongue wink ((In fact, I’m not religious at all - I just wanted to mention this because some people on other forums already thought I choose my Nickname based on religious believes))

Profile
 
 
Posted: 08 May 2007 09:02 AM   [ Ignore ]   [ # 107 ]  
Lab Assistant
RankRank
Total Posts:  248
Joined  02-10-2007

In this case the regex can be removed easily though. This construction has been mentioned before already:

trim(BASEPATH, '/')

Also we could try speeding it up by dropping the explode construction in favor for a combination of strrpos() and substr() like this:

function system_url()
{
    
static $system;
            
    if (!isset(
$system))
    
{
        $system
= trim(BASEPATH, '/');
        
$system = substr($system, strrpos($system, '/') + 1);
        
$system = $this->slash_item('base_url'). $system .'/';
    
}
    
    
return $system;
}

Note that I didn’t test nor benchmark this code, though.

 Signature 

Kohana rocks!

Profile
 
 
Posted: 14 May 2007 08:06 AM   [ Ignore ]   [ # 108 ]  
Lab Assistant
RankRank
Total Posts:  248
Joined  02-10-2007

Two new optimizations submitted:

- [OPTIMIZATION] form_prep() + xml_convert() + convert_xml()
- [OPTIMIZATION] URL Helper > url_title()

Feel free to test and/or improve even more.

 Signature 

Kohana rocks!

Profile
 
 
   
8 of 8
8
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 10:15 AM
Total Registered Members: 119575 Total Logged-in Users: 54
Total Topics: 125796 Total Anonymous Users: 4
Total Replies: 661956 Total Guests: 433
Total Posts: 787752    
Members ( View Memberlist )