php-code-coverage: Version 9 (used with PHPUnit 9.3) is slower than Version 8 (used with PHPUnit 9.2)

Q A
PHPUnit version 9.3
PHP version 7.4
Installation Method Composer

Summary

After upgrading to PHPUnit 9.3, code coverage generation slowed down a lot.

How to reproduce

I’ve experienced this on most of my business repos; I’m sorry I can’t provide a useful test set right now, but I can assure PHPUnit is the only upgraded package here

Until PHPUnit 9.2 (best of 5 runs):

$ /usr/local/bin/php '-d' 'pcov.enabled=1' '/var/www/html/vendor/phpunit/phpunit/phpunit' -v '--coverage-php' '/tmp/CV_ItLP7c' '--configuration' '/var/www/html/phpunit.xml' '--log-junit' '/tmp/PT_uMW9cK'
PHPUnit 9.2.6 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.9 with PCOV 1.0.6
Configuration: /var/www/html/phpunit.xml

.....................................................             53 / 53 (100%)

Time: 00:10.480, Memory: 74.50 MB

OK (53 tests, 259 assertions)

Generating code coverage report in PHP format ... done [00:00.023]

From PHPUnit 9.3 (best of 5 runs):

$ /usr/local/bin/php '-d' 'pcov.enabled=1' '/var/www/html/vendor/phpunit/phpunit/phpunit' -v '--coverage-php' '/tmp/CV_ItLP7c' '--configuration' '/var/www/html/phpunit.xml' '--log-junit' '/tmp/PT_uMW9cK'
PHPUnit 9.3.2 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.9 with PCOV 1.0.6
Configuration: /var/www/html/phpunit.xml
Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

.....................................................             53 / 53 (100%)

Time: 00:17.054, Memory: 96.50 MB

OK (53 tests, 259 assertions)

Generating code coverage report in PHP format ... done [00:00.008]

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 42 (42 by maintainers)

Most upvoted comments

I do not think that using a CachingParser as implemented in 7888a1af43c15ded4f0890eebcb50daf1b7c737f will be useful. Instead, we should try to group the AST processing performed by Node\File and IgnoredLinesFinder in one place so that each file that is executed is parsed only once into an AST node graph which in turn is traversed only once.

We now use PHP-Parser instead of php-token-stream (see https://github.com/sebastianbergmann/php-code-coverage/issues/776 for details) to perform the static analysis required for many of this library’s (and PHPUnit’s) features. The information gained from this is required for traditional line coverage as well as the newly introduced branch and path coverage. The latter are disabled by default and must be explicitly turned on.