Skip to content

perf(runner): reduce subprocess forks in test runner hot path#608

Merged
Chemaclass merged 6 commits intomainfrom
perf/runner-reduce-forks
Mar 14, 2026
Merged

perf(runner): reduce subprocess forks in test runner hot path#608
Chemaclass merged 6 commits intomainfrom
perf/runner-reduce-forks

Conversation

@Chemaclass
Copy link
Copy Markdown
Member

🤔 Background

Related #467

The test runner spawns many unnecessary subprocesses per test (state getter subshells, repeated uname calls, bc/awk for arithmetic, base64 --help detection). These forks dominate wall clock time on large test suites.

💡 Changes

  • Replace state getter $() subshells with direct $_BASHUNIT_* variable access in the runner hot path (~5 forks/test saved)
  • Cache uname result at source time so OS detection functions use a variable instead of forking (~3 forks per is_enabled call saved)
  • Use native bash $(()) arithmetic instead of piping to bc in clock::now shell and date-seconds paths
  • Cache base64 -w flag support once at load time instead of running base64 --help | grep inside every test subshell
  • Replace awk subprocess with bash integer math + printf builtin for duration formatting

Benchmarked at ~16-31% wall clock improvement (4m25s → 3m05s on 847 tests).

Eliminate 5 subshell forks per test by accessing global state variables
directly instead of calling getter functions via $() command substitution.
…orks

Call uname once at source time and reuse the cached value in all OS
detection functions. This eliminates up to 3 subprocess forks per
bashunit::parallel::is_enabled call across the runner hot path.
Replace bashunit::math::calculate (which pipes to bc) with native
bash $(()) arithmetic in the shell and date-seconds clock paths.
Eliminates 1-2 subprocess forks per clock::now call.
Detect base64 -w flag support once at load time instead of running
base64 --help | grep on every test subshell exit. Also use the cached
flag in encode_base64 to avoid redundant command -v and error fallback.
Use bash integer arithmetic and printf builtin instead of spawning
awk subprocesses for formatting test durations in seconds.
@Chemaclass Chemaclass added the enhancement New feature or request label Mar 14, 2026
@Chemaclass Chemaclass self-assigned this Mar 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

✅ Contributor Report

User: @Chemaclass
Status: Trusted contributor (whitelisted)

This user is on the trusted contributors list and was automatically approved.

@Chemaclass Chemaclass enabled auto-merge March 14, 2026 21:35
@Chemaclass Chemaclass merged commit 3ff5963 into main Mar 14, 2026
27 checks passed
@Chemaclass Chemaclass deleted the perf/runner-reduce-forks branch March 14, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants