Squiz Labs Blog - The latest news from the R&D division of Squiz®

Subscribe to our RSS feeds

PHP_CodeSniffer memory improvements to summary report

Memory is the first thing to run out during a really big PHP_CodeSniffer run when a large number of errors and warnings are generated. The reason for this is pretty simple; PHP_CodeSniffer keeps the errors and warnings in memory so it can print consolidated error reports at the end.

The problem is that when you first introduce a coding standard to an existing code base, you're probably going to have a lot of errors and warnings being generated over a lot of files, so you might run out of memory.

So how do you identify the files that need the most work (so you can cut down the number of generated errors) when you can't view the report?

A new memory usage improvement for PHP_CodeSniffer's summary report can help. When you are printing the summary report by itself, PHP_CodeSniffer will no longer generate any error or warning messages. The summary report only shows the number of violations per file and not the detail, so this does not affect the functionality of the summary report in any way.

Note: if you tell PHP_CodeSniffer to also show sources in the summary report (the -s option) the errors and warnings have to be generated and stored, so you will not get any memory usage improvements.

To test this new change, I ran the PEAR coding standard over a Symfony2 checkout. Obviously, Symfony2 doesn't use the PEAR coding standard, so this is a good way to generate a lot of errors and warnings over a large code base.

The PEAR standard generates 29,091 errors and 11,446 warnings in 2007 different files. Here is a summary of the time and memory usage, as reported by PHP_Timer:

Type of run Time (seconds) Memory (Mb)
Old code with warnings
(--report=summary)
56 178.00
Old code without warnings
(--report=summary -n)
56 130.50
New code with warnings
(--report=summary)
51 79.25
New code without warnings
(--report=summary -n)       
51 79.25

When running with the old code, you can save a significant amount of memory by just ignoring warnings. When you do this, PHP_CodeSniffer wont even generate the warning messages and instead just generate the error message. This is a memory usage improvement that was implemented quite a while ago.

But the new code still uses far less memory than the existing code, even when the existing code ignores warnings. With warnings, the memory usage is less than half.

Obviously, these figures will change depending on the number of files being checked and the number of errors and warnings being generated, but you should see some memory improvements when running the summary report from now on.

This change will be released in PHP_CodeSniffer 1.3.6. I don't have a release date set, but it should be in the next couple of weeks. In the meantime, you can grab and run the lastest code from Github.

Squiz Labs

R & D division of Squiz Pty Ltd

Open source web experience management solutions

Squiz Labs is the research and development division of Squiz, the company behind the Squiz Suite of web experience management and development tools.

Our PHP and JavaScript developers are responsible for producing innovative enterprise-quality software while our interface designers and testing team ensure our products both look great and are easy to use.