perf(coverage): single-pass file scan + native regex in extract_functions#644
Merged
Chemaclass merged 2 commits intomainfrom Apr 29, 2026
Merged
Conversation
…ions Address remaining review comments from #636: - Add bashunit::coverage::compute_file_coverage that scans each source file once and resolves hits via the existing single-pass get_all_line_hits helper, removing the O(lines x data) re-scan from report_lcov. - Route get_file_stats, report_text and report_html through the new helper so per-file executable + hit counts are computed once instead of via two independent file scans plus repeated coverage-data greps. - Replace echo | sed and echo | grep subshells in extract_functions with bash native regex matching (BASH_REMATCH) and parameter expansion-based brace counting.
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
Follow-up to #636 / #643. The previous PR collapsed the seven
grepsubshells insidebashunit::coverage::is_executable_lineinto one. Three optimisation suggestions from @objctp's review remained open:report_lcovre-scanned the coverage data file once per source line viaget_line_hits(O(lines × data)).report_text,report_lcov,report_htmlindependently recomputed the same per-file executable + hit counts, each doing two extra file scans.extract_functionsspawnedecho | sed/echo | grepsubshells per line.Changes
bashunit::coverage::compute_file_coverage <file>performs a single source-file pass, resolving hit counts via the already-single-passget_all_line_hitshelper. Returnsexecutable:hit.get_file_stats,report_text,report_htmlnow route throughcompute_file_coverageso per-file executable + hit counts are computed once instead of via two independent file scans plus repeated coverage-data greps.report_lcovreadsget_all_line_hitsonce into a sparse indexed array and emitsDA:entries while tallying executable + hit counts in the same single pass — no more per-line grep over the coverage data file.extract_functionsreplacesecho | sed -nEwith bash native[[ =~ ]]+BASH_REMATCH, and replaces the per-lineecho | grep -c '\\{'/'\\}'subshells with reuse of the already-computed brace-count parameter expansions.