PHPUnit Logo

Sebastian Bergmann, author of PHPUnit, shared an interesting story on phpcc about his experience with caching in PHPUnit. The idea is that caching usually is a solution for making things faster, but how it’s implement might makes things different.

PHPUnit is one of the greatest tools for continuous integration in PHP, but any slowness might affect the development. So things started with PHPUnit 9.3 and the move to use Nikita’s PHP Parser as the foundation for static analysis. This is a great move for static analysis, because PHPUnit now can guess if the code works or not, which will makes the results more accurate and useful.

The issue is that one of the companies using PHPUnit (Crew United) identified slowness in PHPUnit by 90% after upgrading to 9.3, and even caching couldn’t help with the issue. Sebastien explained in details the process of resolving this, and noted :

The first implementation of the cache for the results of static code analysis was too naive.

Cache implementation in PHPUnit now works fine and the performance goes much better, but this adds another lesson learned :

While working on this, I learned that file_exists() is up to a hundred times slower than is_dir() or is_file()

So the obvious decision, is to replace file_exists() with is_file() in your code. The impact probably couldn’t be noticed on small apps, but for large implementations it will help you save lots of time and performance.

Read the whole article at phpcc : Caching makes everything faster. Right?

LEAVE A REPLY

Please enter your comment!
Please enter your name here