Skip to content

perf(signal): sample the signal-hint event every 8th command boundary (#682) - #989

Merged
caomengxuan666 merged 1 commit into
masterfrom
perf/682
Oct 22, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
perf/682

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

  • Issue [perf][P3] shape-independent per-command floor (~2.8us) #682 floor audit (see issue comment for the full ledger): the shape-independent per-command floor on current master is ~3.4-3.5µs per :/true (marginal loop-body cost), essentially unchanged from the ~2.8µs recorded during [perf][P2] Split #619 (1/4): if/case compound-dispatch residual after #624 (~2.5–2.8×, +5.2/+3.7µs per exec) #661. RUBASH_EXEC_PROFILE attribution: dispatch ~2.3µs, ast-side jobs+chain ~1.5-2.4µs, linecmd ~0.6µs.
  • Largest single bounded item: take_pending_signals runs WaitForSingleObject(,0) on the signal-hint event at every command boundary — a real syscall (~0.5-0.7µs measured here) with no upstream analog (GNU's catch_flag is a memory flag set by the kernel handler, trap.c:336 run_pending_traps).
  • The auto-reset event latches a sender's pulse until a wait consumes it, so sampling it every 8th poll loses no delivery; worst-case added latency ~7 boundaries (~25µs) sits far inside the 1024-tick filesystem fallback cadence eventless senders already tolerate. Self-signals (kill $$) bypass the event entirely; take_pending_signals_now (wait-poll, THIS_SH child boundary) stays unthrottled.

Measured (release, rotating interleaved ABBA, min-of-9/11)

probe baseline 6a38de0 candidate Δ
marginal : in loop body 3.43µs/cmd ~3.2µs/cmd −0.4..0.7µs
loop-base-60k 1069.8ms 900.7ms −15.8%
loop-5colon-60k 2100.1ms 1859.3ms −11.5%
flat-colon-80000 978.1ms 942.6ms −3.6% (parse-dominated)
exec-profile jobs bucket (420k cmds) 298ms 99ms −0.47µs/cmd

Out of scope (issue ledger, unchanged)

  • if :;then :;fi ~11.7µs/stmt (3 traversals ≈ 3.9µs/slot)
  • if … >/dev/null ~83.5µs/stmt (+72µs vs plain if): the compound-redirect model splices >> into every leaf, each leaf re-opens the target — fixing that is redirect-architecture work, not a P3 slice
  • top-level per-command parse ~10µs/cmd (noexec slope) — separate subsystem
  • dispatch's ~2.3µs is ~20 sequential semantic checks; no single slice

Test plan

  • issue357 mailbox split 6/6 (incl. busy-loop TERM trap delivery)
  • issue382 6/6, issue343_345 9/9, issue524 12/12
  • cli_tests kill|signal|trap filter 21/21
  • issue526 5/7 — the two -1-signaled asserts fail identically on baseline (Windows has no signaled ExitStatus; pre-existing platform assertion)

Generated with Devin

…#682)

take_pending_signals runs WaitForSingleObject(,0) on the signal-hint event
at EVERY command boundary — a real syscall (~0.5-0.7us measured) inside the
shape-independent per-command floor. The auto-reset event latches a
sender's pulse until a wait consumes it, so sampling it every 8th poll
loses no delivery; worst-case added latency ~7 boundaries (~25us) sits far
inside the 1024-tick filesystem fallback eventless senders already
tolerate. GNU's catch_flag is a memory flag set by the kernel handler
(trap.c:336 run_pending_traps, execute_cmd.c:643 call site) — zero-cost —
so the per-command poll has no upstream analog to amortize against.

Measured (release, rotating interleaved, min-of-11, D-series host):
marginal `:`/`true` in a loop body 3.47/3.63us -> ~3.08us per command
(-0.4..-0.7us/cmd); flat-colon-80000 998.9 -> 941.1ms; jobs profile
bucket 298 -> 99ms over 420k commands.

Delivery batteries green: issue357 mailbox split (6/6 incl. busy-loop
TERM trap), issue382 (6/6), issue343_345 (9/9), issue524 (12/12),
cli_tests kill|signal|trap (21/21). issue526's two -1-signaled asserts
fail identically on baseline (Windows exit-code shape, pre-existing).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit dac428c into master Oct 22, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the perf/682 branch October 22, 2026 03:33
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