Skip to content

perf(runner): remove remaining run_test hot-path forks#782

Merged
Chemaclass merged 4 commits into
mainfrom
feat/774-run-test-hot-path-forks
Jul 13, 2026
Merged

perf(runner): remove remaining run_test hot-path forks#782
Chemaclass merged 4 commits into
mainfrom
feat/774-run-test-hot-path-forks

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #774

Follow-up to #764: the per-test run_test loop still forked for label normalization, clock capture, and repeated parallel::is_enabled checks. This removes those remaining forks with no behaviour change.

💡 Changes

  • Test-label normalization and the per-test clock capture now use fork-free return slots; bashunit::clock::now_to_slot reads EPOCHREALTIME directly on Bash 5.0+.
  • Parallel mode is resolved once after arg parsing instead of re-checking env + OS (and logging) on every is_enabled call.
  • The no-parallel-tests opt-out is detected inside the existing single-pass file scan rather than a separate per-file grep.
  • 100 no-op tests: ~0.78s → ~0.69s (best-of-7, bash 3.2 on macOS); Bash 5.0+ gains more from the clock-fork removal.

Convert the two per-test normalize_test_function_name captures in run_test
to the existing fork-free normalize_test_function_name_to_slot variant,
removing a command-substitution fork on the hot path (and a second on the
hook-failure path). No behaviour change.

Part of #774.
Add bashunit::clock::now_to_slot writing _BASHUNIT_CLOCK_NOW_OUT and make
bashunit::clock::now delegate to it (single source of truth). The shell
branch reads EPOCHREALTIME directly, folding in shell_time so the Bash 5.0+
hot path pays no command-substitution fork; date-seconds forks once instead
of twice. Interpreter/date branches keep one internal fork.

Convert both run_test clock captures (start_time, end_time) to the slot.
_choose_impl selection and the #765 auto-skip behaviour are unchanged.

Part of #774.
bashunit::parallel::is_enabled was re-evaluating the env layer plus four OS
checks (and logging) on every call, several times per test. Resolve it once
after arg parsing via bashunit::parallel::resolve_enabled into
_BASHUNIT_PARALLEL_ENABLED; is_enabled is now a pure global read that falls
back to a fresh, uncached compute only when unresolved (e.g. unit tests that
toggle env directly). The internal_log now fires once, not per call.

Part of #774.
Fold the per-file `grep -q '^# bashunit: no-parallel-tests'` probe into the
existing build_provider_map awk pass, exposing the result via
_BASHUNIT_PROVIDER_MAP_NO_PARALLEL. Removes one grep fork per test file. Also
add the CHANGELOG entry for the #774 hot-path work. No behaviour change.

Closes #774.
@Chemaclass Chemaclass added the enhancement New feature or request label Jul 13, 2026
@Chemaclass Chemaclass self-assigned this Jul 13, 2026
@Chemaclass Chemaclass enabled auto-merge (squash) July 13, 2026 09:52
@Chemaclass Chemaclass merged commit 98dd45f into main Jul 13, 2026
31 checks passed
@Chemaclass Chemaclass deleted the feat/774-run-test-hot-path-forks branch July 13, 2026 10:55
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