perf(coverage): stop forking grep per source line in the report phase - #1031
Merged
Merged
Conversation
Profiling --coverage showed the report, not the capture engine, was half
the wall time and identical for both engines: is_executable_line fell back
to a `grep -E` fork for every line it could not classify in pure Bash, and
every tracked line is classified twice per run (precompute_file_stats, then
report_lcov). 286 source lines cost 1055 grep forks.
The combined regex is replaced by `case` globs reproducing it exactly,
quirks included: inside a POSIX bracket expression a backslash is a literal
member of the set, so `[^\)]` also excludes `\` and `[\{\}]` also matches a
bare line continuation. Verified by running both implementations over the
same 41173 lines across 395 files on Bash 3.2 and 5.3 with zero
disagreements, with the differential harness mutation-tested.
Also surfaces the engine: --verbose reports the one in use, and an explicit
BASHUNIT_COVERAGE_ENGINE=xtrace that the running Bash cannot honour now
warns instead of being dropped silently — the common case on macOS.
Coverage totals are unchanged and still match between --parallel and
sequential for each engine.
Closes #1005
5 tasks
Closed
5 tasks
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.
🤔 Background
Related #1005
Profiling
--coveragebefore optimising anything showed the cost is not where the issue assumed. The report phase is ~50-60% of wall time and is identical for both engines —is_executable_linefell back to agrep -Efork for every line it could not classify in pure Bash, and every tracked line is classified twice per run. 286 source lines cost 1055 grep forks.💡 Changes
caseglobs, removing the per-line fork.--coverageis 1.6x-2.3x faster (interleaved best-of-5: Bash 5.3 xtrace 3213→1396ms, Bash 3.2 trap 4655→2990ms)[^\)]also excludes\and[\{\}]also matches a bare line continuation--verbose, and warn when an explicitBASHUNIT_COVERAGE_ENGINE=xtracecannot be honoured instead of dropping it silently — the common case on macOS's Bash 3.2Verification
Both implementations run over the same 41173 lines across 395 files on Bash 3.2 and 5.3: zero disagreements. The differential harness was mutation-tested — deliberately breaking each rule produced 54 and 4 mismatches respectively, so it discriminates.
Coverage totals unchanged (
129/286trap,174/286xtrace) and still match between--paralleland sequential per engine. The two engines differing is documented expected behaviour, not a regression.Diff coverage from the issue is deliberately not in scope here; filed separately.