Skip to content

perf(runner): stop forking per test when publishing parallel results#813

Merged
Chemaclass merged 5 commits into
mainfrom
perf/parallel-result-file-forks
Jul 16, 2026
Merged

perf(runner): stop forking per test when publishing parallel results#813
Chemaclass merged 5 commits into
mainfrom
perf/parallel-result-file-forks

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Shim-census profiling of --parallel (the mode CI runs everything in) showed ~4 forks per test just to publish each result file: basename, an always-run mkdir -p, and an echo | tr | sed arg-sanitizing pipeline that ran even with no provider args.

💡 Changes

  • Suite dir name via parameter expansion; dir pre-created once per file before workers spawn (a [ -d ] check inside a worker races its siblings); sanitizing skipped when there are no provider args.
  • A 10-test parallel run drops from 61 to 21 forks (basename/tr/sed 30 → 0, mkdir 12 → 3); the remaining per-test fork is the uniqueness-guaranteeing mktemp.
  • Shim-based regression test added; provider-args path unchanged and covered by existing provider tests. No behaviour change.

parse_result_parallel runs once per test in every parallel worker and forked
~4 times per test: basename for the suite dir name, mkdir -p for a dir that
already existed after the first test, and an 'echo | tr | sed' pipeline that
sanitized provider args even when there were none.

- Derive the suite dir name with parameter expansion.
- Pre-create the dir once per file before workers spawn (a [ -d ] check inside
  a worker races its siblings, so every worker would still pay the fork), and
  keep a guarded mkdir -p in the worker as fallback.
- Skip arg sanitizing when there are no provider args; the pipeline still runs
  for real provider args.

A 10-test parallel run drops from 61 to 21 forks (basename/tr/sed 30 -> 0,
mkdir 12 -> 3); the remaining per-test fork is the mktemp that guarantees a
unique result file. Parallel is the mode CI runs everything in.

No behaviour change.
The census failed on Linux CI with a bare count; asserting on the shim log's
content makes the failure identify which binary forked and how often.
The Linux CI census caught a per-test sed the macOS profile missed: on systems
whose clock is fork-free (Linux date), per-test execution time is shown, and
right-aligning it strips the colored line's ANSI codes through 'echo | sed' —
one fork per passing test.

strip_ansi_to_slot now handles short (<=1KB) backslash-free strings in pure
bash: CSI sequences are removed segment-wise with the exact sed semantics
(only 'm'/'K' finals swallowed, other finals keep their printable residue),
then remaining control bytes are swept with a bounded pattern substitution.
Long or backslash-bearing inputs keep the echo -e + sed path, so large
assert payloads never hit bash's quadratic substitution.
The Bash 3.0 CI census (no bc in that image) caught math::calculate forking
sed on every integer expression to strip leading zeros before $((...)). Clock
durations — the common no-bc caller — never contain a leading zero, so a case
precheck keeps that path fork-free and only forks sed when a 0-prefixed number
is actually present.
Brace the expansion adjacent to a literal bracket in the CSI stripper and
replace the write-only for-loop counter with a countdown the loop reads;
CI runs shellcheck across all files while 'make sa' covers a subset.
@Chemaclass
Chemaclass merged commit 52750c5 into main Jul 16, 2026
37 checks passed
@Chemaclass
Chemaclass deleted the perf/parallel-result-file-forks branch July 16, 2026 04:11
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.

1 participant