Skip to content

Delete the source code from the token cache #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

scottbrady
Copy link

Delete the source code from the token cache when we're done calculating statistics. This greatly reduces memory usage when running coverage against many files. When running tests against a subset of my codebase, this change reduced memory usage from ~900MB to ~300MB. I paired on this work with my coworker, Mark French.

…ng statistics. This greatly reduces memory usage when running coverage against many files. Paired with Mark French.
@@ -169,6 +169,8 @@ class PHP_CodeCoverage_Report_HTML_Node_File extends PHP_CodeCoverage_Report_HTM
);

$this->calculateStatistics();

PHP_Token_Stream_CachingFactory::delete($path);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In most situations both the Clover XML and HTML report are generated. Both report generators leverage the token cache.

@scottbrady
Copy link
Author

So this becomes a balance between memory usage and disk IO. I'm running into serious memory usage issues right now trying to run code coverage against my entire code base. php-code-coverage uses over 1GB of memory then hits the memory limit and dies. I'm willing to take the extra hit of a file read to significantly reduce memory usage. I haven't noticed any difference in code coverage generation time from this change.

@mrmarkfrench
Copy link

That's true, but it requires that the tokenized representation of ALL source files be kept in memory for the entire duration of BOTH report generation runs. This delete allows only a single file to be kept in working memory at a time, which prevents the current behavior of steadily growing (read: runaway) memory consumption.

@sebastianbergmann
Copy link
Owner

Yes, it is a tradeoff between memory and CPU/disk. That is why the caching can be turned off for PHP_CodeCoverage.

@scottbrady
Copy link
Author

That's great to hear caching can be disabled. I looked through the code and don't see anything that would make caching happen conditionally. I must be missing something... how do I turn it off? Thanks.

@sebastianbergmann
Copy link
Owner

PHPUnit 3.6 introduces a cacheTokens attribute in the XML configuration to turn off the token cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants