From 9918cb67716e5be32090aee162688823cfd38087 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Tue, 14 Jul 2026 15:04:46 +0200 Subject: [PATCH] perf(runner): detect OS with a single uname fork at cold start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit check_os.sh forked `uname` twice per load: once at module scope and again inside check_os::init (invoked at load). init sets _BASHUNIT_UNAME before any reader runs, so the module-scope call was dead weight — one redundant fork on every one of the acceptance suite's 258 nested bashunit cold starts. Closes #798 --- CHANGELOG.md | 1 + src/check_os.sh | 2 -- tests/unit/check_os_test.sh | 8 ++++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab83dc82..ad3f0a9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - `--jobs auto` / `-j auto` caps parallel concurrency at the CPU core count (portable across Linux/macOS/BSD); the default stays unlimited (#766) ### Changed +- Faster cold start: `check_os` detects the OS with a single `uname` fork at load instead of two (matters across the acceptance suite's nested `bashunit` runs). No behaviour change (#798) - Faster test execution: removed the remaining round-2 fork leftovers — `wait_for_job_slot` counts running background jobs without forking `wc` on every poll (145 -> 0 `wc` forks across a small parallel run), and `check_duplicate_functions` folds its per-file grep+awk+sort+uniq scan into a single awk pass. No behaviour change (#761) - `assert_equals`/`assert_same` failures with multiline values now render a git word-diff below the header (requires git, opt out with `BASHUNIT_NO_DIFF=true`, respects `--no-color`); machine reports keep the raw values (#777) - Faster `assert_match_snapshot`: fork-free success path, byte-compatible snapshots; 500 snapshot assertions ~7.5s -> ~3.0s on bash 3.2 (#775) diff --git a/src/check_os.sh b/src/check_os.sh index 46558e91..2ca74e7b 100644 --- a/src/check_os.sh +++ b/src/check_os.sh @@ -40,8 +40,6 @@ function bashunit::check_os::is_nixos() { grep -q '^ID=nixos' /etc/os-release 2>/dev/null } -_BASHUNIT_UNAME="$(uname)" - function bashunit::check_os::is_linux() { [ "$_BASHUNIT_UNAME" = "Linux" ] } diff --git a/tests/unit/check_os_test.sh b/tests/unit/check_os_test.sh index 061217fb..ab488eed 100644 --- a/tests/unit/check_os_test.sh +++ b/tests/unit/check_os_test.sh @@ -78,6 +78,14 @@ function test_not_alpine_is_not_busybox() { assert_general_error "$(bashunit::check_os::is_busybox)" } +function test_module_load_detects_os_with_a_single_uname_call() { + bashunit::spy uname + + source "$BASHUNIT_ROOT_DIR/src/check_os.sh" + + assert_have_been_called_times 1 uname +} + function test_nproc_uses_nproc_when_available() { bashunit::mock nproc echo "8"