perf(runner): reduce subprocess forks in test runner hot path#608
Merged
Chemaclass merged 6 commits intomainfrom Mar 14, 2026
Merged
perf(runner): reduce subprocess forks in test runner hot path#608Chemaclass merged 6 commits intomainfrom
Chemaclass merged 6 commits intomainfrom
Conversation
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.
Contributor
✅ Contributor ReportUser: @Chemaclass This user is on the trusted contributors list and was automatically approved. |
JesusValeraDev
approved these changes
Mar 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 Background
Related #467
The test runner spawns many unnecessary subprocesses per test (state getter subshells, repeated
unamecalls,bc/awkfor arithmetic,base64 --helpdetection). These forks dominate wall clock time on large test suites.💡 Changes
$()subshells with direct$_BASHUNIT_*variable access in the runner hot path (~5 forks/test saved)unameresult at source time so OS detection functions use a variable instead of forking (~3 forks peris_enabledcall saved)$(())arithmetic instead of piping tobcinclock::nowshell and date-seconds pathsbase64 -wflag support once at load time instead of runningbase64 --help | grepinside every test subshellawksubprocess with bash integer math +printfbuiltin for duration formattingBenchmarked at ~16-31% wall clock improvement (4m25s → 3m05s on 847 tests).