Caching makes everything faster. Right?
This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).
Sebastian Bergmann shares a real-world performance debugging story from PHPUnit development. PHPUnit 9.3 introduced PHP-Parser for static analysis in php-code-coverage, causing a ~90% slowdown. A caching layer was added to mitigate this, but a user (Martin Völker) reported the cache actually made things 3x slower. Through profiling with Xdebug and a video conference, the root cause was identified: the cache stored results in five separate files per source file, and the `ignoredLinesFor()` method was being called once per test per covered file, causing massive repeated disk I/O. The fix consolidated cache files and eliminated redundant reads. An additional lesson: `file_exists()` can be up to 100x slower than `is_file()` in PHP. The story highlights that caching can hurt performance when implemented naively, and that benchmarking is needed alongside functional tests.
Table of contents
Better information thanks to PHP-ParserOh no. It's slow!A bad cache is worse ...So what caused this?Last but not leastSort: