Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Nov 5, 2025

before this PR

➜  slow-coverage-xml1 git:(main) ✗ hyperfine 'php coverage-xml.php'
Benchmark 1: php coverage-xml.php
  Time (mean ± σ):     11.744 s ±  0.072 s    [User: 10.387 s, System: 1.305 s]
  Range (min … max):   11.641 s … 11.854 s    10 runs

after this PR

➜  slow-coverage-xml1 git:(main) ✗ hyperfine 'php coverage-xml.php'
Benchmark 1: php coverage-xml.php
  Time (mean ± σ):     11.594 s ±  0.073 s    [User: 10.266 s, System: 1.275 s]
  Range (min … max):   11.511 s … 11.762 s    10 runs

running my benchmark based on phpstan-src codebase recorded coverage data.

this change is based on the observation that the inlined addTest method is invoked ~10 million times, when running code-coverage even on a small portion of the phpstan-src codebase

XDEBUG_MODE=coverage php tests/vendor/bin/paratest --coverage-xml=tmp/coverage-xml tests/PHPStan/Analyser

grafik

@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.82%. Comparing base (9838486) to head (75f911e).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1102      +/-   ##
============================================
+ Coverage     88.53%   88.82%   +0.29%     
+ Complexity     1393     1391       -2     
============================================
  Files            98       98              
  Lines          4874     4652     -222     
============================================
- Hits           4315     4132     -183     
+ Misses          559      520      -39     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sebastianbergmann
Copy link
Owner

Nice! Can I bother you to squash this into a single commit with a sensible commit message?

@staabm
Copy link
Contributor Author

staabm commented Nov 5, 2025

here we go

Comment on lines +31 to +39
$writer = new XMLWriter;
$writer->openMemory();
$writer->startElementNs(null, $this->contextNode->nodeName, 'https://schema.phpunit.de/coverage/1.0');
$writer->writeAttribute('nr', $this->line);

foreach ($tests as $test) {
$writer->startElement('covered');
$writer->writeAttribute('by', $test);
$writer->endElement();
Copy link
Contributor Author

@staabm staabm Nov 5, 2025

Choose a reason for hiding this comment

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

my feeling is, if we would work with plain strings instead of XMLWriter we may be even faster.

is this something you would be open for?

Copy link
Owner

Choose a reason for hiding this comment

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

No.

@sebastianbergmann sebastianbergmann merged commit ba70759 into sebastianbergmann:main Nov 5, 2025
16 checks passed
@staabm staabm deleted the faster branch November 5, 2025 12:37
@staabm
Copy link
Contributor Author

staabm commented Nov 5, 2025

I have 2 more PRs which improve processing speed in a similar way. you may want discuss them with arne:

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