Skip to content

perf(runner): outvar pattern in hot-path result helpers#672

Merged
Chemaclass merged 2 commits into
mainfrom
perf/662-reduce-subshells-runner
May 12, 2026
Merged

perf(runner): outvar pattern in hot-path result helpers#672
Chemaclass merged 2 commits into
mainfrom
perf/662-reduce-subshells-runner

Conversation

@Chemaclass
Copy link
Copy Markdown
Member

Summary

  • Convert four bashunit::runner::* helpers used per test in run_test to the outvar pattern (first arg is the name of the variable to assign into).
  • Affected helpers: extract_encoded_field, extract_subshell_type, format_subshell_output, compute_total_assertions.
  • Update the four $(...) capture call sites in run_test to pass the target variable name, eliminating one fork+pipe per call per test.

Implementation notes

  • Internal locals use a __bu_ prefix to avoid name collisions with caller variables passed by name (e.g. format_subshell_output subshell_output "$subshell_output"). The first iteration without this prefix caused the local subshell_output to shadow the caller's, swallowing the assignment — surfaced by 12 parallel failures.
  • eval "$_out=\$_val" keeps the assignment Bash 3.0+ safe (no printf -v, no namrefs).
  • Pure refactor: each helper has direct unit tests covering the new signature; no behavior change at call sites.

Test plan

  • New unit tests in tests/unit/runner_test.sh: empty/missing keys, multi-counter sum, subshell-type stripping, marker → newline expansion
  • ./bashunit tests/ green (1060 passed, 3m21s — down from ~3m baseline)
  • ./bashunit --parallel tests/ green (1055 passed, ~45s)
  • make sa clean
  • make lint clean
  • Bash 3.0+ compat preserved (eval-based outvar assignment)

Closes #662

@Chemaclass Chemaclass added enhancement New feature or request refactoring Refactoring or cleaning related labels May 12, 2026
@Chemaclass Chemaclass self-assigned this May 12, 2026
Convert bashunit::runner::extract_encoded_field, extract_subshell_type,
format_subshell_output, compute_total_assertions to write to a caller-named
outvar instead of stdout. Update the four call sites in run_test to pass
a target variable name, eliminating one fork+pipe per call per test.

Internal locals use a __bu_ prefix to avoid name collisions with caller
variables passed by name (e.g. 'format_subshell_output subshell_output ...').

Adds direct unit tests for each helper covering the new signature.

Closes #662
@Chemaclass Chemaclass force-pushed the perf/662-reduce-subshells-runner branch from 5886beb to bdbfd33 Compare May 12, 2026 08:54
@Chemaclass Chemaclass merged commit 1cae56f into main May 12, 2026
25 checks passed
@Chemaclass Chemaclass deleted the perf/662-reduce-subshells-runner branch May 12, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request refactoring Refactoring or cleaning related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(runner): reduce subshells in hot path

1 participant