-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Zend\Loader\ClassMapAutoloader - Performance improvement #5716
Comments
@fedys is that true also for larger maps? |
Absolutely, in my production environment the RESULTING map has over 2000 records with aprox. 40 custom modules(each provides its map). Performance gaing is 10-15ms after use of foreach(before: 190ms, after: 175ms). |
http://3v4l.org/gAt9X 10 entries A little depending on the PHP Version, but most of the time |
Just verified it as well here
That is... curious... |
According to @DaveRandom, the slowness is caused by copy-on-write going on at each call of I've added a test that tries to do a single
|
Composer doesn't seem to be affected since it has a single classmap when optimizing autoloading. |
👍 great work! |
@Ocramius i am trying to figure out the code differences from your testds. mind sharing the actual code from the test above? thanks a bunch!! |
@franz-deleon something like this i think //singleArrayMerge
array_merge($config1, $config2, $config3, ....$config22);
//singleArrayMergeCallUserFuncArray
call_user_func_array('array_merge', array($config1, $config2, ....$config22));
//arrayMergePerformance
$config = array();
$config = array_merge($config, $config1);
$config = array_merge($config, $config2);
//...
$config = array_merge($config, $config22); |
What about the performance of array_replace(), or even |
What was puzzling to me, is that 5.5.8 is 36% faster with Apparently 5.5.6 introduced: "Improved performance of array_merge() and func_get_args() by eliminating useless copying.", so the mystery is solved. The performance gap might be huge enough to sanction a |
@DASPRiD hahaha... it seems that Anyways, |
@Thinkscape the 5.5.8 improvement is magic by @dstogov |
@franz-deleon sorry, thought I had pasted a link. use https://gist.github.com/Ocramius/8399625 to write additional tests |
Also interessting that foreach performance dropped significantly since 5.5.6 |
@fedys can you check my updated tests? |
Your updated tests seem to cover all use cases. Please try replace key 'index' . $i with some random string with at least 50 chars to 100 chars. Do the same for the values. $this->bigMap1['index123'] = 123 will become: $this->bigMap1['c4ca4238a0b923820dcc509a6f75849b6f4922f455'] = '621f1454cacf995530ea53652ddf8fb9908279ebbf1f9b250ba689db6a0222b'. This should be closer to real case. |
@fedys verified with larger maps, and it seems like the results stay consistent, with |
@Ocramius I agree with you. The + operator seems to be best choice. I have just noticed the arraySumPerformance() should be:
which is semantically right and is a bit faster. |
@fedys could you provide a PR for this enhancement? |
Related to #6285. |
This issue has been closed as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html |
array_merge() in Zend\Loader\ClassMapAutoloader::registerAutoloadMap() method causes significant performace lost. Replace $this->map = array_merge($this->map, $map); with foreach ($map as $key => $value) { $this->map[$key] = $value; }.
The text was updated successfully, but these errors were encountered: