Skip to content

perf(coverage): single-pass file scan + native regex in extract_functions#644

Merged
Chemaclass merged 2 commits intomainfrom
perf/636-coverage-followup-optimizations
Apr 29, 2026
Merged

perf(coverage): single-pass file scan + native regex in extract_functions#644
Chemaclass merged 2 commits intomainfrom
perf/636-coverage-followup-optimizations

Conversation

@Chemaclass
Copy link
Copy Markdown
Member

@Chemaclass Chemaclass commented Apr 29, 2026

Background

Follow-up to #636 / #643. The previous PR collapsed the seven grep subshells inside bashunit::coverage::is_executable_line into one. Three optimisation suggestions from @objctp's review remained open:

  1. report_lcov re-scanned the coverage data file once per source line via get_line_hits (O(lines × data)).
  2. report_text, report_lcov, report_html independently recomputed the same per-file executable + hit counts, each doing two extra file scans.
  3. extract_functions spawned echo | sed / echo | grep subshells per line.

Changes

  • New bashunit::coverage::compute_file_coverage <file> performs a single source-file pass, resolving hit counts via the already-single-pass get_all_line_hits helper. Returns executable:hit.
  • get_file_stats, report_text, report_html now route through compute_file_coverage so per-file executable + hit counts are computed once instead of via two independent file scans plus repeated coverage-data greps.
  • report_lcov reads get_all_line_hits once into a sparse indexed array and emits DA: entries while tallying executable + hit counts in the same single pass — no more per-line grep over the coverage data file.
  • extract_functions replaces echo | sed -nE with bash native [[ =~ ]] + BASH_REMATCH, and replaces the per-line echo | grep -c '\\{' / '\\}' subshells with reuse of the already-computed brace-count parameter expansions.

…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.
@Chemaclass Chemaclass self-assigned this Apr 29, 2026
@Chemaclass Chemaclass added the refactoring Refactoring or cleaning related label Apr 29, 2026
@Chemaclass Chemaclass merged commit 6afbded into main Apr 29, 2026
30 checks passed
@Chemaclass Chemaclass deleted the perf/636-coverage-followup-optimizations branch April 29, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Refactoring or cleaning related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant