Skip to content

Do not build code unit map when test has no coverage targets#1244

Closed
janedbal wants to merge 1 commit into
sebastianbergmann:12.5from
janedbal:lazy-target-mapper-for-empty-target-collections
Closed

Do not build code unit map when test has no coverage targets#1244
janedbal wants to merge 1 commit into
sebastianbergmann:12.5from
janedbal:lazy-target-mapper-for-empty-target-collections

Conversation

@janedbal

@janedbal janedbal commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Problem

  • The Test\Target\Mapper is built even when no test in the entire suite uses #[CoversClass] / #[UsesClass].
  • Building the mapper means MapBuilder::build() statically analyses every file in the filter, so a suite that requests any coverage report pays a full source-tree analysis per PHP process, even though the resulting map is never consumed.
  • PHPUnit passes an empty TargetCollection to CodeCoverage::validate() / append() for every test that declares no coverage targets, and both call sites build the mapper before noticing the collection is empty.

Real-world numbers (app with ~24k files under <source>, 5 fast unit tests, --coverage-cobertura, PCOV, cold cache):

wall time peak memory
latest 12.5.7 53.5 s 657 MB
with this change 10.6 s 426 MB

Without this patch, we are unable to migrate from PHPUnit 11 to 12+ as our overall CI time for tests inscreases from ~7 mins to ~12 mins.

Notes:

  • Generated report is byte-identical.
  • Projects that do use #[CoversClass]/#[UsesClass] are unaffected.

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.31%. Comparing base (4b61c53) to head (3b3a16d).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff              @@
##               12.5    #1244      +/-   ##
============================================
- Coverage     89.39%   89.31%   -0.09%     
- Complexity     1404     1407       +3     
============================================
  Files           105      105              
  Lines          4724     4726       +2     
============================================
- Hits           4223     4221       -2     
- Misses          501      505       +4     

☔ View full report in Codecov by Harness.
📢 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
Copy Markdown
Owner

Merged manually, thank you.

@janedbal

janedbal commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Ref, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants