Skip to content

perf(beamrt): Wave 3D-36 selective-receive thunk fast path & #462 P2/P3 closure - #468

Merged
CommaBot merged 1 commit into
mainfrom
feat/wave3d36-beamrt
Dec 6, 2026
Merged

CommaBot merged 1 commit into
mainfrom
feat/wave3d36-beamrt

Conversation

@CommaBot

@CommaBot CommaBot commented Dec 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Wave 3D-36 targets CP#9's #2 real beamrt hotspot (beamrt_recv_peek_thunk 9.59% + beamrt_recv_next_thunk 3.58% = 13.17%, paired with beamrt_bif_cmp_thunk 9.31% in selective-receive {^Ref, _} scans) and closes all 2 P2 + 4 P3 items from Fable's #462 review. Strict file boundary: crates/beamrt/src/** only (6 files, +276/-120).

1. Selective-receive & local HDR_REF hot-path optimizations (asm_ctx.rs, mailbox.rs)

  • 64-bit fused peeked_next + peeked store/load: Promoted Peeked to #[repr(u32)] right after 8-byte-aligned peeked_next (enforced by compile-time const _ assertions PEEKED == NEXT + 4, NEXT.is_multiple_of(8), ORDINARY == 1, target_endian == "little"). beamrt_recv_peek_thunk packs node_next | (ORDINARY << 32) into a single 64-bit store (bts r10, 32 / orr x10, x10, #0x100000000), and beamrt_recv_next_thunk reads both via a matching 64-bit load (clean L1 store-to-load forwarding).
  • Deferred pending_exit check & drop per-peek examined RMW: Moved pending_exit check in beamrt_recv_peek_thunk to the empty-queue 30: label (matching recv_peek_impl in exports.rs:1435-1458 1:1) and removed the 64-bit examined read-modify-write on the naked-asm fast path.
  • Hoist 2-word local HDR_REF exact equality to Fast Path 0 in beamrt_bif_cmp_thunk (both x86_64 and aarch64): Straight-line 10-instruction path in the entry 64B i-cache line with zero taken jumps for {^Ref, _} selective-receive scans, with the non-matching-second-operand tail (7:) kept cold.

2. Fable #462 2 P2 + 4 P3 closure

  • P2-1 (scheduler.rs, dirty.rs): Extracted pure should_skip_idle_spin(...) helper with full truth-table assertions + #[cfg(test)] spin_loop_entries: AtomicUsize so runtime_oversub_backoff_skips_dirty_handoff_spin deterministically fails if the rt.oversub.is_active(now) guard is reverted; added deterministic synthetic-clock unit test dirty_preempt_invokes_on_preempt_and_sets_cooldown covering on_preempt + cooldown.
  • P2-2 (controlled-load 5-round ABBA bisect): Tested (A) both-sides park vs (B) scheduler-only park vs (C) dirty-only park under taskset -c 0,1 (BEAMRT_SCHEDULERS=2) across solo, combined, and solo_oversub (pinned external CPU burners). Kept (A): under deterministic external oversubscription (solo_oversub), (A) (268.28 ms) beats (B) (376.32 ms, +40.27% slower) and (C) (400.10 ms, +49.13% slower).
  • P3-1 (io_poller.rs): Wrapped PENDING_WORK in crate::pad::CachePadded<AtomicUsize> to eliminate false sharing with POLLERS.
  • P3-2 (net/prim_inet.rs): Gated fstat (st_dev, st_ino) assertion with #[cfg(target_os = "linux")] and verified via getsockname on non-Linux (macOS/BSD fstat returns 0 for inet sockets).
  • P3-3 / P3-4 (io_poller.rs, net/prim_inet.rs, scheduler.rs): Updated io_poller.rs comment with CP#9 2-sched forced-4-shard -6.6% / -9.7% trade-off; replaced "TLS path" with "thread-local buffer"; removed redundant normal_budget_ns alias.

Verification

Controlled-load 5-round ABBA (pvg-office-1, Ryzen 7 PRO 8845HS, taskset -c 0,1, BEAMRT_SCHEDULERS=2, 10 paired samples each)

  • O(N) selective-receive scan (mbox_scan_bench, depth=20,000, iters=1,000 = 20M scans/run, loadavg 23.14 -> 23.04):
    • BASE (357ca95e): median 216.43 ms (10.82 ns/msg, min 165.76, max 283.54)
    • OPT (Wave 3D-36): median 200.42 ms (10.02 ns/msg, min 131.17, max 252.51) → -7.40% (1.080x)
  • P2-2 dirty_cpu NIF handoff 3-way bisect (prim_buffer:find_byte_index/2, loadavg 23.04 -> 20.66, lower ms = faster):
    Mode BASE (357ca95e) (A) both-sides park (B) sched-only park (C) dirty-only park
    solo (2 dirty procs on 2 cores) 160.24 ms 213.28 ms 145.33 ms (-31.9% vs A) 132.02 ms (-38.1% vs A)
    combined (2 dirty + 2 normal CPU procs) 213.46 ms 258.22 ms 137.01 ms (-46.9% vs A) 194.39 ms (-24.7% vs A)
    solo_oversub (+2 pinned external CPU burners) 261.12 ms 268.28 ms 376.32 ms (+40.3% vs A) 400.10 ms (+49.1% vs A)
    • Note: under deterministic external oversubscription (solo_oversub), (A) avoids spinning away CPU quantum and beats (B) by 40.3% and (C) by 49.1%; (B)/(C) only win when cores are not externally contended. Therefore (A) is retained.
  • Idle-3s CPU: OPT_IDLE_3S_CPU_PCT=0.00% (< 1% gate).

All 6 Local Gates (on pvg-office-1)

  1. ./scripts/check-aeneas-subset.sh — PASS
  2. ./scripts/check-beamrt-ssot.sh — PASS
  3. cargo clippy -p beamrt --all-targets -- -D warnings — PASS
  4. cargo test -p beamrt --lib — PASS (282 passed; 0 failed)
  5. cargo test -p beamrt --test runtime_tests -- --test-threads=1 — PASS (64 passed; 0 failed)
  6. cargo test -p beamrt --test ssot_matrix_tests — PASS (6 passed; 0 failed)

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…P3 closure

- Selective-receive hot path (asm_ctx.rs, mailbox.rs):
  - Promote Peeked to #[repr(u32)] adjacent to 8-byte-aligned peeked_next
    with compile-time layout assertions; pack peeked_next + Peeked::Ordinary
    into a single 64-bit store in beamrt_recv_peek_thunk and a matching
    64-bit load in beamrt_recv_next_thunk (eliminates store-forwarding stall).
  - Defer pending_exit check in beamrt_recv_peek_thunk to the empty-queue
    path (matching recv_peek_impl semantics) and drop per-peek examined RMW
    on the naked-asm fast path.
  - Hoist 2-word local HDR_REF exact equality to Fast Path 0 in
    beamrt_bif_cmp_thunk (x86_64 and aarch64) so selective-receive {^Ref, _}
    scans stay straight-line in the entry cache line with zero taken jumps.
- Close all Fable #462 2 P2 + 4 P3 items:
  - P2-1 (scheduler.rs, dirty.rs): extract pure should_skip_idle_spin helper
    + deterministic spin_loop_entries assertion in
    runtime_oversub_backoff_skips_dirty_handoff_spin, and deterministic
    synthetic-clock unit test dirty_preempt_invokes_on_preempt_and_sets_cooldown.
  - P2-2: controlled taskset -c 0,1 5-round ABBA bisect of (A)/(B)/(C)
    confirms (A) both-sides park beats (B) by 40.3% and (C) by 49.1% under
    deterministic external oversubscription.
  - P3-1 (io_poller.rs): CachePadded<AtomicUsize> for PENDING_WORK.
  - P3-2 (net/prim_inet.rs): Linux-only fstat (st_dev, st_ino) assertion
    with getsockname verification on non-Linux.
  - P3-3 / P3-4 (io_poller.rs, net/prim_inet.rs, scheduler.rs): accurate
    clamp(1, 4) comment, 'thread-local buffer' wording, drop redundant
    normal_budget_ns alias.
@CommaBot
CommaBot merged commit 78aaffe into main Dec 6, 2026
3 checks passed
@CommaBot
CommaBot deleted the feat/wave3d36-beamrt branch December 6, 2026 00:24
CommaBot added a commit that referenced this pull request Dec 6, 2026
Co-authored-by: Heyang Zhou <6104981+losfair@users.noreply.github.com>
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.

2 participants