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

PcovDriver causing 2x slowness of coverage run after upgrade to phpunit 9.5 #876

Closed
indreka opened this issue Oct 27, 2021 · 3 comments
Closed

Comments

@indreka
Copy link

indreka commented Oct 27, 2021

Q A
php-code-coverage version 9.2.7
PHP version 7.4.11
Driver PCOV
Xdebug version (if used) -
Installation Method Composer
Usage Method PHPUnit
PHPUnit version (if used) 9.5.10

After switching to phpunit 9.5 a 2x slowness was witnessed (4.5 min => 9min). Previous reports/issues about new AST parser library caused some false assumptions. Testing with static cache did not improve speed much nor did cache warming improve things to the original levels.

After digging through the coverage logic and adding all sorts of time measurements to the coverage collecting steps, the main slownesses seems to come from ProcessedCodeCoverageData->markCodeAsExecutedByTestCase() and ProcessedCodeCoverageData->initializeUnseenData()
The functions themselves are not big and don't do anything obviously slow.
Adding more debug info showed that the list of classes being processed was 500 files with 20 000 lines and this happened for each test execution, even if test actually called only one short function that has 1 line in it.

After more checks it seems that PCOV extension is returning list of all seen files during the whole run, even if 0 code was actually executed since last call to clear(), causing lots of overhead to the functions that then try to analyze the results.

Adding following code to PcovDriver->stop() after \pcov\clear(); to ignore file entries where ALL lines are marked as not executed restores the speed to original levels:

      $notExecutedFilter = static function ($val): bool
      {
        return $val === self::LINE_NOT_EXECUTED;
      };
      //PCOV driver keeps returning files that have no lines executed in them, clear them away here to avoid overhead later
      foreach ($collect as $fileName => $lines)
      {
        if (count(array_filter($lines, $notExecutedFilter)) === count($lines))
        {
          unset($collect[$fileName]);
        }
      }
@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Oct 27, 2021

CC @dvdoug @krakjoe

@krakjoe
Copy link
Contributor

krakjoe commented Oct 27, 2021

Not an upstream issue, looks related to other changes in the driver.

@sebastianbergmann
Copy link
Owner

Not an upstream issue, looks related to other changes in the driver.

Thank you for looking into this, Joe, and so quickly.

dvdoug added a commit to dvdoug/php-code-coverage that referenced this issue Oct 27, 2021
dvdoug added a commit to dvdoug/php-code-coverage that referenced this issue Oct 27, 2021
dvdoug added a commit to dvdoug/php-code-coverage that referenced this issue Oct 27, 2021
dvdoug added a commit to dvdoug/php-code-coverage that referenced this issue Oct 28, 2021
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

No branches or pull requests

3 participants