Skip to content
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

Smarter filter use #747

Merged
merged 2 commits into from
May 13, 2020

Conversation

dvdoug
Copy link
Contributor

@dvdoug dvdoug commented May 13, 2020

It is well-known that Xdebug requires a lot of resources in order to do it's work and running a test suite under Xdebug to generate code coverage data is therefore a lot slower than running it without.

For this reason, PHPUnit has the ability for a user to generate an Xdebug filter script which can be used on subsequent executions to significantly speed up coverage by telling Xdebug to ignore code not in the whitelist e.g. in vendor. Since it requires manual setup work from them and is not "out of the box", most users do not do this.

Since the filter script must be executed before the other files are executed, it is not possible to have a fully automatic version of this. However it is possible to get something fairly close, perhaps 95% as efficient by automatic means.

When the Xdebug driver class is constructed, it receives the whitelist filter configuration. By initiating the built in Xdebug filter at this time, part of PHPUnit is already loaded, part of php-code-coverage is already loaded and it's too late for Xdebug to be able to exclude them. However, the rest of PHPUnit, the rest of php-code-coverage, the other phpunit/* codebases (notably php-token-stream), the rest of vendor and the contents of test can all be excluded i.e. actually most things.

This is essential for path coverage (#380) as the Xdebug memory requirements are otherwise very very large. It also allows most users (those not using a prepend script) to get a significant speed boost even when using standard line-based coverage.

Those who do use a prepend script can continue to do so to obtain absolute maximum performance, since the whitelist of their filter script and the whitelist set here at runtime will the same list this will not undo anything for them.

A similar, but much smaller gain can also be had for PCOV - the PCOV driver currently outputs coverage data for all files which are then filtered later by php-code-coverage. Since we have the list of files we're interested in, we can have the output filtering done inside the PCOV extension itself.

@codecov
Copy link

codecov bot commented May 13, 2020

Codecov Report

Merging #747 into master will increase coverage by 0.49%.
The diff coverage is 14.28%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #747      +/-   ##
============================================
+ Coverage     81.96%   82.46%   +0.49%     
+ Complexity      843      842       -1     
============================================
  Files            36       35       -1     
  Lines          2484     2469      -15     
============================================
  Hits           2036     2036              
+ Misses          448      433      -15     
Impacted Files Coverage Δ Complexity Δ
src/Driver/PCOV.php 33.33% <0.00%> (+3.33%) 3.00 <1.00> (ø)
src/Driver/Xdebug.php 0.00% <0.00%> (ø) 14.00 <3.00> (-1.00)
src/CodeCoverage.php 72.16% <100.00%> (ø) 181.00 <0.00> (ø)
src/Driver/Driver.php

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1894727...43674d1. Read the comment docs.

@dvdoug
Copy link
Contributor Author

dvdoug commented May 13, 2020

Psalm error is bogus, I am not sure how to get rid of that :/

@sebastianbergmann sebastianbergmann merged commit c0fb088 into sebastianbergmann:master May 13, 2020
@sebastianbergmann
Copy link
Owner

I'll take care of it.

@dvdoug dvdoug deleted the smarter_filter_use branch May 13, 2020 14:04
@dvdoug
Copy link
Contributor Author

dvdoug commented May 13, 2020

Awesome, thanks!

@sebastianbergmann
Copy link
Owner

Those who do use a prepend script can continue to do so to obtain absolute maximum performance

I do not believe that maintaining --dump-xdebug-filter and --prepend is worthwhile anymore.

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.

2 participants