Skip to content

test(runner): pin the clock probe to once per run, not once per worker - #1363

Merged
Chemaclass merged 1 commit into
mainfrom
feat/1353-resolve-clock-impl-once
Sep 9, 2026
Merged

test(runner): pin the clock probe to once per run, not once per worker#1363
Chemaclass merged 1 commit into
mainfrom
feat/1353-resolve-clock-impl-once

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #1353

Resolving the clock implementation happened inside a $( ), so the resolved value died with that subshell and every --parallel worker re-probed. On a shell without EPOCHREALTIME the probe forks perl, so it scaled one-for-one with the tests — and fired even with per-test timing off, since deciding that timing is off is what asks whether the clock is expensive.

The behaviour is already fixed. #1358 converted clock::init to now_to_slot for its own reasons, which resolves the impl in the main shell before any worker is dispatched. Measured on a 500-test file, macOS arm64, bash 3.2.57:

init --no-parallel --parallel
old 3 502
new 2 2

💡 Changes

  • Nothing pinned that, so this adds the two guards. The unit test is the invariant itself — init must leave _BASHUNIT_CLOCK_NOW_IMPL set in the caller. The acceptance test is the differential the issue asked for: eight times the tests must not cost more probes. Both fail against the old init (7 probes against 42).
  • A differential rather than a budget, because a platform whose clock is EPOCHREALTIME or date forks no perl at all — comparing two sizes still fails loudly if the count starts tracking the test count.
  • perf-fork-budget.md stated the parallel budget from a sequential census fixture, which cannot see a per-worker cost by construction. It now says so.

https://claude.ai/code/session_01EXYWTGLjf7qM8Ru3GakDRm

Resolving the clock implementation used to happen inside a `$( )`, so
the resolved value died with that subshell and the main shell was left
empty. Under --parallel every worker inherited that empty value and
re-probed; on a shell without EPOCHREALTIME the probe forks `perl`, so
the count scaled one-for-one with the tests. Measured here on a
500-test file, macOS arm64, bash 3.2.57:

  old init   --no-parallel    3     --parallel  502
  new init   --no-parallel    2     --parallel    2

It fired even with per-test timing off, because deciding that timing is
off is what asks whether the clock is expensive, and answering that
resolves the impl.

The behaviour is already fixed: #1358 converted clock::init to
now_to_slot for its own reasons, which resolves the impl in the main
shell before any worker is dispatched. Nothing pinned it there, so this
adds the two guards.

The unit test is the invariant itself -- init must leave
_BASHUNIT_CLOCK_NOW_IMPL set in the caller -- and the acceptance test is
the differential the issue asked for: eight times the tests must not
cost more probes. Both fail against the old init (7 probes against 42).

A differential rather than a budget, because a platform whose clock is
EPOCHREALTIME or `date` forks no `perl` at all; comparing two sizes still
fails loudly if the count starts tracking the test count.

perf-fork-budget.md stated the parallel budget from a sequential census
fixture, which cannot see a per-worker cost by construction. It now says
so.

Closes #1353

Claude-Session: https://claude.ai/code/session_01EXYWTGLjf7qM8Ru3GakDRm
@Chemaclass Chemaclass added the enhancement New feature or request label Sep 9, 2026
@Chemaclass Chemaclass self-assigned this Sep 9, 2026
@Chemaclass
Chemaclass merged commit 8beb173 into main Sep 9, 2026
37 checks passed
@Chemaclass
Chemaclass deleted the feat/1353-resolve-clock-impl-once branch September 9, 2026 10:38
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