Problem
With the report phase down to one awk invocation each for stats (#1088) and
LCOV (#1090), report_text is now the largest phase left — and most of it is
not work, it is forks.
bashunit::coverage::get_color_for_class is a case that prints one of three
colour constants, and the per-file table calls it as $(...):
color=$(bashunit::coverage::get_color_for_class "$class")
Measured on Bash 3.2 arm64:
| 128 files | |
|---|
report_text total | 253 ms |
| the colour subshells alone | 168 ms |
| the same decision inline, no fork | 15 ms |
The same pattern appears per function under BASHUNIT_COVERAGE_SHOW_FUNCTIONS
(report_text.sh, html_file.sh), where it is paid ~700 times on this repo,
and twice more in diff.sh for get_coverage_class.
Fix
A return slot, as .claude/rules/bash-style.md prescribes and as
_derive_file_stats already does for the percentage and the class: the helper
writes _BASHUNIT_COVERAGE_COLOR_OUT and the caller reads it. The existing
$()-returning helpers stay for any caller that wants them.
Expected: report_text 253 ms to roughly 100 ms, and the per-function paths
drop the same fork each.
Problem
With the report phase down to one awk invocation each for stats (#1088) and
LCOV (#1090),
report_textis now the largest phase left — and most of it isnot work, it is forks.
bashunit::coverage::get_color_for_classis acasethat prints one of threecolour constants, and the per-file table calls it as
$(...):color=$(bashunit::coverage::get_color_for_class "$class")Measured on Bash 3.2 arm64:
report_texttotalThe same pattern appears per function under
BASHUNIT_COVERAGE_SHOW_FUNCTIONS(
report_text.sh,html_file.sh), where it is paid ~700 times on this repo,and twice more in
diff.shforget_coverage_class.Fix
A return slot, as
.claude/rules/bash-style.mdprescribes and as_derive_file_statsalready does for the percentage and the class: the helperwrites
_BASHUNIT_COVERAGE_COLOR_OUTand the caller reads it. The existing$()-returning helpers stay for any caller that wants them.Expected:
report_text253 ms to roughly 100 ms, and the per-function pathsdrop the same fork each.