[eluser]Nate Wagar[/eluser]
Recently, my team had some issues with page performance on our server. After quite a bit of benchmarking and debugging, I discovered that the performance hit came straight from the stock CodeIgniter Model code, more specifically, _assign_libraries.
It's impossible to notice on most pages, however we have two pages that load 1500 models (rough estimate) for display. At this level, the overhead is quite visible, thanks to our scalability over speed SPARC processors.
When I discovered this, I started playing and made it do this instead:
Code:
var $db;
var $benchmark;
var $session;
var $load;
function _assign_libraries($use_reference = TRUE)
{
$CI = & get_instance();
$this->db =& $CI->db;
$this->benchmark =& $CI->benchmark;
$this->session =& $CI->session;
$this->load =& $CI->load;
}
This took page execution from 14 seconds down to 6, and memory footprint from 18MB to 8MB. Obviously quite an improvement.
Knowing that this would cause problems down the line, I plan to tweak it even further:
Code:
function _assign_libraries($use_reference = TRUE)
{
$this->CI = & get_instance();
}
and adjust all Models accordingly.
So my question is: Why aren't things done like this in the first place? (Or, will this break something that I don't expect?) Not being familiar with all the inner workings of CodeIgniter, I can't begin to answer these questions myself.