Repository navigation
Inject unloaded files once at the merge point, not once per process - #1255
Merged
Merged
Conversation
Discovering tracked files and simulating the ones that were never loaded lived as private helpers on the SimpleCov singleton, reading root, globs and criteria straight off it. The next commit moves the injection to the merge step, which runs on behalf of processes whose configuration it does not share, so the logic has to take what it needs as arguments. SimpleCov::UnloadedFileInjector now owns discovery and injection. SimpleCov.inject_unloaded_files is the seam the merger will call, public for that reason and marked @api private. No behaviour changes: every process still injects its own unloaded files exactly as before.
inject_unloaded_files skips only what the current process loaded, so every worker in a parallel run simulated nearly the whole project and the merge discarded all but one copy of each file. Only the union of what every process loaded says what was really never loaded, so the injection now happens in ResultMerger.create_result. Over 400 tracked files with 40 loaded by no worker, a 16-worker run goes from 6040 simulations taking 3.15s across the workers to 40 taking 0.024s once, flat in worker count. A single process, and any run with merging false, pays what it did before, and resultsets shrink from 13.4MB to 800KB at 16 workers. The merge needs to know which files were tracked, and that configuration lives in whichever process ran SimpleCov.start. A standalone collate never ran it, so deferring alone would have left it with no glob to expand and silently dropped every untested file: 90 files at an inflated 36.88% where there should be 400 at 8.30%. Each process therefore records the paths it was told to track into its resultset, and the merge unions those. Discovery costs a Dir.glob per process, 1.26ms over 400 files, against the simulation it replaces. The key is omitted when empty and absent from resultsets written by earlier versions, which already carry the files their process injected and so merge unchanged. Merged coverage and the not-loaded set are identical at every worker count. Knowing exactly which files were injected also supersedes the line-count heuristic for them, so a never-loaded branchless file is now flagged under a branch-only run, which that heuristic cannot do because it has no line data to judge by. ResultMerger::UnloadedFiles holds the merge half. ResultMerger.valid_results went unused and is removed. Refs #1250.
Four places where deferring injection left the merge reading state that belonged to whichever process produced the resultset. Same shape as the glob problem the tracked-path list already solved, so they are fixed the same way: what the producer knew goes in the resultset, and the merge derives the rest from the data it is merging. A process records what it was told to track, did not load, and would have reported. Two things were leaking. Result#to_hash serializes coverage after filtering, so a file the process loaded and then filtered out was absent from the stored coverage while still listed as tracked, and the merge simulated it back in as never loaded. And a tracked file the process never loaded but its own filters exclude was recorded too, so a merge that does not share those filters reported a file the producer deliberately left out. Filters that decide from the path alone are now applied when recording. A block filter is handed the source file and may consult coverage that does not exist yet, so those still fall to the merging process, which is why Filter#path_only? defaults to false. Injection read branch_coverage? and friends off the merging process, which for `simplecov merge` never ran SimpleCov.start at all. An injected file given fewer tables than the files beside it is what inflates the percentage #1059 fixed, so the criteria now come from the merged data. The configuration is consulted only when the merge carried no files and there is nothing to be consistent with. Tracked paths were collected before drop_expired_results, so a resultset dropped for being past merge_timeout still contributed paths and a file only a stale run ever tracked was simulated in at 0%. merge_valid_results now yields the surviving entries, and both merge entry points collect from those. Each fix has a spec that fails against the behaviour it replaces.
sferik
force-pushed
the
prototype-merge-point-injection
branch
from
August 7, 2026 19:20
f5078ae to
b7bfde4
Compare
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.
#1252 made each simulation cheaper. This stops them happening N times.
inject_unloaded_filesskips only the files the current process loaded, so every worker in a parallel run simulates nearly the whole project and the merge discards all but one copy of each. Only the union of what every process loaded says what was really never loaded, so the injection now happens once, inResultMerger.create_result.Over 400 tracked files with 40 of them loaded by no worker, under line plus branch plus method coverage:
Flat in worker count rather than linear. A single process, and any run with
merging false, pays what it paid before. Per-worker resultsets also shrink from 13.4MB to 800KB at 16 workers, since they no longer each carry a simulated copy of the whole project.Deferring the injection alone is not enough, and this is the part worth reviewing closely. The merge needs to know which files were tracked, and the
cover/track_filesconfiguration lives in whichever process ranSimpleCov.start. A standaloneSimpleCov.collatenever ran it, so it has no glob to expand. Collating the same resultsets in a process with no glob configured:Forty untested files silently vanish and coverage inflates. So each process now records the paths it was told to track into its resultset, and the merge unions them. Discovery costs one
Dir.globper process, 1.26ms over 400 files, against the simulation it replaces.The key is omitted when empty, and absent from resultsets written by earlier versions. Those already carry the files their process injected, and injection skips paths already present, so they merge unchanged.