AOEpeople / Aoe_ClassPathCache

Class path cache for Magento autoloader
http://www.fabrizio-branca.de/magento-class-path-cache.html
Open Software License 3.0
49 stars 16 forks source link

Improve file mode. #7

Closed colinmollenhour closed 10 years ago

colinmollenhour commented 11 years ago
tmotyl commented 11 years ago

Hi Colin, Did you do some performance tests whether include is faster then serialize? Can you share your results and methodology? I decided to go with serialize after testing few different scenarios, so it would be really interesting to investigate why you got different results. Two other changes looks OK for me.

colinmollenhour commented 11 years ago

@tmotyl I did not do tests.. I figured the include method would always take advantage of opcode caches whether it be eaccelerator, APC, or the Zend OpCache which will be standard in PHP 5.5. I have to think that loading an array from an opcode cache that is already in binary form would be faster than reading a file (even though it is almost certain to be cached in the filesystem) and deserializing a string into the same..

If you tested without an opcode cache I can see how serialize might be faster.. Did you test with or without an opcode cache? I think it is a good assumption that all users will have opcode caches and if they don't then they are the wrong people to be optimizing for anyway.

tmotyl commented 11 years ago

I did all my tests with APC enabled. I will look for the script I used for a benchmark and will post the link here, so we can discuss it further.

rgoytacaz commented 11 years ago

dont forget about this! :+1:

tmotyl commented 11 years ago

Hi, Here is a gist with benchmark comparing different ways to store the cache. https://gist.github.com/tmotyl/ceaef8315913366a3e2d and here are the results I got https://gist.github.com/tmotyl/d5bac80c36ef813d4e13 Cheers Tymoteusz

colinmollenhour commented 11 years ago

Thanks for sharing @tmotyl.

It looks like serialize is indeed much faster than var_export and include with APC enabled is much slower than I would expect. In fact, it is only slightly faster than eval(file_get_contents())! So my guess is that APC only stores code symbols in opcode form and leaves arrays in some serialized form that isn't very fast afterall..

You APC numbers are off because you ran the benchmark on CLI where APC is disabled by default. When disabled there will be no errors but the cache will not actually save anything. This explains why your apc_store is so much faster than apc_fetch. Running on a web server the apc_store is slightly slower than apc_fetch.

The method you used to generate the PHP file for the include method is the old one. The newer one I used made use of PHP's var_export method which is only marginally faster. I also tried putting an unserialize call inside a php file and that was faster than the native array! Wtf..

So in short: You were right, file_get_contents and serialize are faster than loading a PHP file even with APC enabled.

colinmollenhour commented 11 years ago

K, I force pushed an updated commit that uses serialize/unserialize.

tmotyl commented 11 years ago

@colinmollenhour Thanks for your valuable insight! I'm pretty sure I did the tests with APC enabled on the CLI level, but I don't have this virtualbox any more, so I can't confirm. Looking forward for the updated patch :)

colinmollenhour commented 11 years ago

I already updated this pull request with a force push to the same branch: ac382be

colinmollenhour commented 10 years ago

Fabrizio, I see your latest commit adds the file flag revalidation, but it does not have the removal of tmp files on failed rename. Any reason for this? Why not just merge the branch?