Skip to content

perf(runner): reduce subshells in hot path #662

@Chemaclass

Description

@Chemaclass

Context

src/runner.sh contains ~98 $(...) command substitutions. Many sit in the per-test hot path, forking a subshell on every test execution. Suite runs ~80s sync / ~22s parallel; subshell overhead is a sizable chunk.

Hot-path offenders

  • bashunit::runner::extract_encoded_field (src/runner.sh:49) — called per field per test
  • bashunit::runner::extract_subshell_type (src/runner.sh:78)
  • bashunit::runner::format_subshell_output (src/runner.sh:84)
  • bashunit::runner::compute_total_assertions (src/runner.sh:62)

Param expansion already used in places — push further. Common pattern:

foo=$(bashunit::runner::extract_subshell_type "$out")

Refactor to fill an outvar (Bash-3 safe via eval or namref-free assignment) instead of capturing subshell stdout:

bashunit::runner::extract_subshell_type out "$subshell_output"
# function body: eval "$1=\"\${2%%]*}\""; eval "$1=\"\${$1#[}\""

Or inline the param expansions at call sites where the helper is one-liner.

Acceptance

  • No $(...) capture in per-test hot path of runner.sh for the listed helpers
  • All tests green (./bashunit tests/)
  • Parallel tests green (./bashunit --parallel tests/)
  • Bash 3.0+ compat preserved (no namrefs, no declare -n)
  • Benchmark before/after wall-clock on tests/unit/ posted in PR

Notes

  • Pre-compiled regex _BASHUNIT_RUNNER_PARSE_RESULT_REGEX (runner.sh:5) already exists — extend usage if it reduces helper calls.
  • Validate with PS4='+ \$EPOCHREALTIME ' bash -x ./bashunit tests/unit/<file>.sh 2>trace to confirm hotspots pre/post.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestrefactoringRefactoring or cleaning related

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions