Repository navigation
Stop matching the :nocov: regex twice on every classified line - #1253
Merged
sferik merged 1 commit intoAug 7, 2026
Merged
Conversation
SimpleCov.result simulates coverage at exit for every file a track_files or cover glob matched that the process never loaded. It is per-process work, so a parallel run pays it once per worker, and since each worker loads only a fraction of the code, nearly every worker simulates nearly the whole project. Skipping the branch and method synthesis takes the bulk of that out for a line-coverage-only run; classification is what remains, and it is paid under every configuration. LinesClassifier#classify ran the :nocov: regex twice per line: once to toggle skipping and once inside not_relevant_line?. A marker is always a comment, so the cheaper whitespace-or-comment test now gates the token match, and a line of real code -- most of a source file -- no longer pays for it at all. Measured over SimpleCov's own lib/ (104 files, 8,845 lines), median of three runs each: classify alone 48.31 -> 43.36 ms -10% simulate, line coverage only 67.58 -> 60.09 ms -11% simulate, synthesis enabled 85.30 -> 79.41 ms -7% benchmarks/simulate_coverage.rb covers this path, which had no benchmark before -- only collate and Result did, so nothing measured the per-process work at exit. The rescue in LinesClassifier.no_cov_line? is no longer reachable from classify, since an invalid byte sequence now fails the whitespace test first. SourceFile::SkipChunks still calls it directly on raw source, so it keeps its rescue and gains a direct spec. The spec added alongside pins that `synthesize: false` skips the Prism parse outright rather than parsing and discarding it, which is the claim behind that flag.
sferik
added a commit
to andriytyurnikov/simplecov
that referenced
this pull request
Aug 7, 2026
Only CHANGELOG.md conflicted, where this branch and simplecov-ruby#1253 each appended a bullet to the Unreleased Performance section. Kept both. The classification bullet goes first because it reads "once the synthesis above is skipped" and has to stay next to the synthesis bullet it refers to. The merge-side bullet follows, which also leaves the section running per-process synthesis, then per-process classification, then merging. The code merged clean: main's two new commits touch only lib/simplecov/lines_classifier.rb and its spec, which this branch does not. Full rake is green on the result.
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.
Follow-on to #1252, on the same per-process path. Skipping the branch and method synthesis took the bulk of the cost out of a line-coverage-only run; classification is what remains, and unlike the synthesis it is paid under every configuration.
LinesClassifier#classifymatched the:nocov:regex twice for every line — once to toggle skipping, once insidenot_relevant_line?:A
:nocov:marker is always a comment, so the cheaper whitespace-or-comment test now gates the token match, and a line of real code — most of a source file — no longer pays for it at all.Measured over SimpleCov's own
lib/(104 files, 8,845 lines), median of three runs:Classification output is unchanged; the existing specs pin it.
benchmarks/simulate_coverage.rbis new. Nothing measured this path before — onlycollateandResulthad benchmarks, so the per-process work at exit was invisible.Two smaller things in here:
The
rescueinLinesClassifier.no_cov_line?is no longer reachable fromclassify, since an invalid byte sequence now fails the whitespace test first.SourceFile::SkipChunksstill calls it directly on raw source, so it keeps its rescue and gains a direct spec.One spec added to
simulate_coverage_spec.rb:synthesize: falseskips the Prism parse outright rather than parsing and discarding. The existing specs assert the tuples come back empty, which parsing-then-discarding would also satisfy — the point of the flag is that the parse never happens.Refs #1250.