Repository navigation
Cut unloaded-file injection cost, fix 100% coverage in merged reports - #1252
Merged
Merged
Conversation
Simulating a tracked-but-unloaded file statically enumerates its branch and method tuples (#1059), and the Prism parse behind that is over half the cost of simulating a file. It ran even for the default line-coverage-only configuration, where Combine::FilesCombiner and the statistics both drop the tuples unread, and it is paid once per tracked file in every process, which is why it shows up on large parallel runs. SimulateCoverage.call now takes a synthesize: keyword and the injection site passes branch_coverage? || method_coverage?. On a 400 file synthetic project the default configuration's injection pass goes from 0.526 to 0.222 ms per file. Line classification is identical either way, and suites with either criterion enabled are unaffected. Reported with measurements by @andriytyurnikov. Refs #1250.
SourceFile::Statistics reports 0% rather than a misleading 100% when a never-loaded file has no branch or method data (#902), but the rule keys off a loaded: flag that only the single-process path set. ResultMerger.create_result omitted not_loaded_files, so every file in a merged report claimed to have been loaded and the rule never fired there. A tracked file no process loaded and that contains no conditionals, say a constants file caught by a cover glob, reported 100% branch and method coverage. Only branchless files exposed it, since #1059's synthesized tuples already give anything with a conditional a real 0%. The flag cannot be carried across, since Result#to_hash writes only coverage and a timestamp, so the merged result re-derives it from the merged line counts using the same "did any line execute" signal Combine::FilesCombiner reconciles on. This also matters for the previous commit, which keeps synthesized tuples out of resultsets written by line-coverage-only runs: a later collate with branch coverage enabled now reports those files as 0% rather than 100%. Line counts only carry that signal when the run produces them. A branch-only or method-only run gets none from Coverage for the files it loaded, so judging on their absence would mark every file in the report not loaded and report 0% for the branchless ones. SimulateCoverage now omits line data under those criteria too, mirroring Coverage, which keeps a simulated file from looking like one a sibling process loaded once the two merge. Nothing is flagged there rather than misflagged. Reported with an exemplary diagnosis by @andriytyurnikov. Refs #1250.
sferik
force-pushed
the
unloaded-file-injection-cost-and-merge-flags
branch
from
August 7, 2026 12:45
e48b443 to
813cecf
Compare
This was referenced Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two changes from #1250, one per commit:
Simulating a tracked-but-unloaded file statically enumerates its branch and method tuples so unloaded files contribute to those denominators symmetrically with their lines (#1059). The Prism parse behind that is over half the cost of simulating a file, and it ran unconditionally, including for the default line-coverage-only configuration where
Combine::FilesCombinerandSourceFile::Statisticsboth discard the tuples unread. It is paid once per tracked file in every process, which is why it shows up on large parallel runs.SimulateCoverage.callnow takes asynthesize:keyword (defaulting totrue, so it stays a pure function of the file), andinject_unloaded_filespassesbranch_coverage? || method_coverage?. The criterion decision lives at the call site.Measured end to end through
add_not_loaded_fileson a 400 file, 26,000 line synthetic project:Line classification is identical either way.
SourceFile::Statisticsreports 0% rather than a misleading 100% when a never-loaded file has no branch or method data (#902), but the rule keys off aloaded:flag that only the single-process path ever set.ResultMerger.create_resultbuilt itsResultwithoutnot_loaded_files, which defaults to an emptySet, so every file in a merged report claimed to have been loaded and the rule could never fire there.The flag cannot simply be carried across, because
Result#to_hashwrites only coverage and a timestamp, so it never reaches.resultset.json. The merged result now re-derives it from the merged line counts using the same "did any line execute" signalCombine::FilesCombineralready reconciles on.A tracked file that no process loaded and that contains no conditionals, say a constants file caught by a
coverglob:Only branchless files exposed this, since #1059's synthesized tuples already give anything containing a conditional a real 0%, which is likely why it went unnoticed.
Line counts only carry that signal when the run produces them. A branch-only or method-only run gets none from
Coveragefor the files it loaded, so judging on their absence would mark every file in the report not loaded and report 0% for the branchless ones.SimulateCoveragenow omits line data under those criteria too, mirroringCoverage, so a simulated file cannot be mistaken for one a sibling process actually loaded once the two merge. Nothing is flagged under those configurations rather than misflagged, which leaves them exactly as they are onmain. This adds aSimpleCov.line_coverage?predicate alongsidebranch_coverage?andmethod_coverage?, counting:oneshot_linebecauseResultAdapterturns its executed-line list back into a line array.The second commit closes a hole the first would otherwise open. Gating the synthesis keeps synthesized tuples out of resultsets written by line-coverage-only runs, and a later
collatewith branch coverage enabled would then find those files empty. On the old merge path, where the #902 rule is dead, they would report 100%. With the flag re-derived they correctly report 0%.Each worker still simulates every tracked file it did not personally load, so the work stays O(N) in worker count. That is the larger architectural change discussed in the issue, and it is worth re-measuring first: after this PR a default run pays roughly 0.22 ms/file instead of 0.47, so the remaining headroom is smaller than the issue's figures suggest.