Skip to content

perf: shave shape-independent per-command floor edges (#682) - #2160

Merged
caomengxuan666 merged 3 commits into
masterfrom
perf/682-command-floor
Oct 30, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
perf/682-command-floor

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

References #682 (partial — floor attribution landed; the structural remainder stays on the issue as the ledger; keeping it open per the #989 disposition).

Three bounded, behavior-neutral slices off the per-command boundary, from a two-round RUBASH_EXEC_PROFILE attribution pass (flat 50k :, release): dispatch 2.44us (matcmd 1.24, expand 0.23, …), chain 0.86, jobs 0.66, linecmd 0.44 per command. The funnel floor itself is structural (matches the #989 ledger); these remove the boundary's avoidable fixed costs.

Changes

  1. Stamped-by-caller line stamp (ast_exec.rs, command_execute.rs, mod.rs, init.rs, command_substitution.rs): the execute_ast loop stamped __RUBASH_CURRENT_LINE/__RUBASH_CMD_START_LINE and then execute_command re-stamped the identical pair from the same node + unchanged ambient. GNU stamps line_number ONCE per command (execute_cmd.c SET_LINE_NUMBER; :936 for cm_simple). New Executor::pre_stamped_line: Cell<bool>: armed by the loop immediately before its funnel call, consumed on entry (nested execute_command / pipeline stages / trap actions always stamp), suppressed when the funnel's trap-scope branch would stamp debug_trap_function_line, and suppressed when a DEBUG fire / debugger seam ran this iteration (run_debug_trap leaves the action's lines behind, so the post-trap restamp is GNU's :936 behavior and must run).
  2. Queue allocation removed (trap_exec.rs): Vec::with_capacity(4) → Vec::new() in run_pending_signal_traps — one malloc/free per command boundary removed; capacity unobservable.
  3. Windows lock-free self-queue gate (kill.rs): rubash#437's PENDING_ANY gate existed only on the unix drain (take_all_signals); the Windows take_pending_signals locked SELF_SIGNALS at every boundary unconditionally. Flag stores are now unconditional across platforms (queue_self_signal, requeue_pending_signals), and the Windows branch gates the mutex on the flag with the same acquire/release + drain-then-clear discipline; a delivery racing the clear is delivered, never dropped. GNU basis: trap.c:336 catch_flag is a memory check, not a lock/syscall.

Measured (interleaved A/B, min-of-36, Xeon w5-3433, release, per command /50000)

case pristine this branch delta
loop 1× : 6188 ns 5808 ns −6.1%
loop 2× : 9202 ns 8822 ns −4.1%
loop 1× true 6400 ns 6132 ns −4.2%
if :; then :; fi 13369 ns 13285 ns −0.6%
: >/dev/null 18384 ns 18374 ns −0.1%
flat 50k all-in 10123 ns 9885 ns −2.4%
marginal : (the floor) 3014 ns 3014 ns unchanged — structural

Battery A/B vs pristine 2503977

  • Delivery battery (perf(signal): sample the signal-hint event every 8th command boundary (#682) #989 bar): issue357 1/1, issue382 9/9, issue343_345 6/6, issue524 12/12, issue1473 6/6 — 34/34 green.
  • executor_tests: failure set on this branch (27) is a strict subset of pristine's (28) — zero new failures.
  • cli kill/signal/trap 20/21; issue0085-family 1/4; issue1363 19/21; issue1493 0/1 — every failure reproduced identically on pristine (pre-existing, environment-bound).
  • LINENO behavioral probe (loops, multi-line commands, functions, DEBUG-trap $LINENO, assignments): byte-identical output on both binaries.

Disclosure

cargo fmt cannot run on this host (rustfmt spawn fails with os error 206 — the documented hook precedent), so the commit was created with --no-verify equivalence; the diff is hand-formatted to rustfmt style. (Also: this branch was published via the git-data API because the github.com HTTPS git endpoint was unreachable from this host; the tree sha 7fdbe32c matches the locally verified commit byte-for-byte.)

Three bounded, behavior-neutral slices off the per-command boundary,
from a two-round RUBASH_EXEC_PROFILE attribution pass (flat 50k `:`,
release): dispatch 2.44us (of which matcmd 1.24, expand 0.23), chain
0.86, jobs 0.66, linecmd 0.44 per command. The funnel floor itself is
structural (matches the #989 ledger); these remove the boundary's
avoidable fixed costs:

1. stamped-by-caller line stamp (ast_exec.rs, command_execute.rs):
   the execute_ast loop stamped __RUBASH_CURRENT_LINE/
   __RUBASH_CMD_START_LINE and then execute_command re-stamped the
   identical pair from the same node + unchanged ambient. GNU stamps
   line_number ONCE per command (execute_cmd.c SET_LINE_NUMBER;
   :936 for cm_simple). New Executor::pre_stamped_line (Cell<bool>):
   armed by the loop immediately before its funnel call, consumed on
   entry (nested execute_command / pipeline stages / trap actions
   always stamp), suppressed when the funnel's trap-scope branch would
   stamp debug_trap_function_line, and suppressed when a DEBUG fire or
   debugger seam ran this iteration (run_debug_trap leaves the
   action's lines behind — trap_exec.rs:1325 — so the post-trap
   restamp is GNU's :936 behavior and must run).

2. run_pending_signal_traps (trap_exec.rs): Vec::with_capacity(4)
   heap-allocated at every command boundary with no delivery pending;
   Vec::new() defers the allocation to the first push (capacity is
   unobservable).

3. Windows lock-free self-queue gate (kill.rs): rubash#437's
   PENDING_ANY gate existed only on the unix drain (take_all_signals);
   the Windows take_pending_signals locked SELF_SIGNALS at every
   boundary unconditionally. Flag stores are now unconditional across
   platforms (queue_self_signal, requeue_pending_signals), and the
   Windows branch gates the mutex on the flag with the same
   acquire/release + drain-then-clear discipline; a delivery racing
   the clear is delivered, never dropped. Moves Windows closer to
   GNU's catch_flag memory check (trap.c:336) instead of a syscall.

Measured (interleaved A/B, min-of-36, Xeon w5-3433, release):
loop 1x `:` 6188->5808 ns/iter (-6.1%), loop 2x `:` 9202->8822 (-4.1%),
`true` 6400->6132, flat 50k 10123->9885 ns/cmd (-2.4%); every case
improved or tied; the funnel marginal floor itself (~3.0us) is
unchanged and stands as the structural ledger.

Battery A/B vs pristine 2503977: issue357/382/343_345/524/1473
delivery battery 34/34 green; executor_tests failure set on this
branch (27) is a strict SUBSET of pristine's (28) — zero new
failures; cli kill/signal/trap 20/21 with the 1 failure identical on
pristine; issue1363 2, issue0085-family 3, issue1493 1 failures all
reproduced identically on pristine (pre-existing, environment-bound);
LINENO behavioral probe byte-identical on both binaries.

Disclosure: cargo fmt cannot run on this host (rustfmt spawn fails
with os error 206, the documented hook precedent), so committed with
--no-verify; diff is hand-formatted to rustfmt style.
@caomengxuan666
caomengxuan666 merged commit 3ac7133 into master Oct 30, 2026
9 checks passed
@caomengxuan666
caomengxuan666 deleted the perf/682-command-floor branch November 2, 2026 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant