Skip to content

perf(dataplane): steady-state fast path at the response point (v5 S2c, default-off) - #317

Merged
bb7133 merged 1 commit into
mainfrom
perf/fastpath-s2c-response
Oct 7, 2026
Merged

bb7133 merged 1 commit into
mainfrom
perf/fastpath-s2c-response

Conversation

@bb7133

@bb7133 bb7133 commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Stacks conceptually on S2b (command point, merged 2ec605dc). Extends the inline fast path to the response-ACK point, default-off behind TIPROXY_FSM_FASTPATH.

Why

Measured on current main: for the online write-heavy / small-single-packet-response model, each command has ~1 non-opt#5-bypassed await_effect(ForwardResponseToClient) round-trip — the same magnitude as the command-forward round-trip that S2b fast-pathed for −6.9% CPU. The response packet is already flushed to the client (session_engine.rs:3646) before this round-trip, so it is pure FSM bookkeeping with no I/O.

Mechanism (design converged with CodexM5)

The command's own forward permit is held across response_rounds (pending >= 1), so S2b's pending == 0 gate is unreachable. New core API try_inline_commit_excluding(&fwd_permit, event, expected, shutdown):

  • fwd_permit is a capability/liveness witness — Rust's borrow proves it is not dropped; Arc::ptr_eq proves it belongs to this core, so pending == 1 means that single registration is exactly this permit (no redirect/drain/control/in-flight sync).
  • Identity check, open/shutdown read, speculative clone transition, exact-effect match, write-back — all in one lock critical section (no raw pending escapes → no TOCTOU).
  • Registers no new permit (no post-commit I/O); fwd_permit keeps the floor.
  • Same-core mismatch / pending != 1 / sealed / shutdown / effect mismatch → unchanged slow path. LocalInfile always slow. Prepared/cursor commands keep an in-flight sync (pending >= 2) → auto-fallback.

Verification

  • Flag-off keeps the exact slow-path ack-permit lifetime; fast-path on/off wire traces byte-identical (scripts/fastpath-trace-ab.sh).
  • Response point fires once per single-packet-response command under the flag (0 off).
  • New gate tests: inline commit (no new permit, same FSM state as slow transition, terminal round) + every fallback (pending != 1, wrong-gate witness, sealed, shutdown, effect mismatch).
  • All dataplane suites green, fmt + clippy clean.

Hit-rate / CPU A/B on a production-like workload is a separate measurement step (as #146 was for S2b).

🤖 Generated with Claude Code

…, default-off)

Extends the S2b command-point inline fast path to the response-ACK point. For
a steady command whose response packet is already flushed to the client, the
`events`→loop→`await_effect(ForwardResponseToClient)` round-trip is pure FSM
bookkeeping with no I/O, so it can be committed inline under the core lock.

Because the command's own forward permit is held across `response_rounds`
(`pending >= 1`), the S2b `pending == 0` gate is unreachable here. Instead a new
core API `try_inline_commit_excluding(&fwd_permit, event, expected, shutdown)`
takes the command's permit as a capability/liveness witness: Rust's borrow
proves it is not dropped, `Arc::ptr_eq` proves it belongs to this core, so
`pending == 1` means that single registration is exactly this permit and nothing
else is outstanding (no redirect/drain/control/in-flight sync). The identity
check, open/shutdown read, speculative clone transition, exact-effect match and
write-back all run in one lock critical section; no raw `pending` escapes (no
TOCTOU). The inline commit registers NO new permit — the already-flushed packet
means no post-commit I/O and `fwd_permit` keeps the floor. A same-core identity
mismatch, `pending != 1`, a sealed/shutdown core or an effect mismatch all fall
back to the unchanged slow path. `LocalInfile` (different ack) always takes the
slow path. Prepared/cursor commands keep an in-flight sync permit so `pending`
is >= 2 and they fall back automatically.

Default-off behind `TIPROXY_FSM_FASTPATH`. Flag-off keeps the exact slow-path
permit lifetime (ack permit held to the end of the loop iteration). Verified:
fast-path on/off wire traces byte-identical; the response point fires once per
single-packet-response command under the flag (0 off); all dataplane suites,
fmt and clippy clean. New gate tests cover the inline commit (no new permit,
same FSM state as the slow transition, terminal round too) and every fallback
(pending != 1, wrong-gate witness, sealed, shutdown, effect mismatch).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bb7133
bb7133 force-pushed the perf/fastpath-s2c-response branch from f2dac10 to 49e7d57 Compare October 7, 2026 11:48
@bb7133
bb7133 marked this pull request as ready for review October 7, 2026 16:07
@bb7133
bb7133 merged commit 1a8f5c9 into main Oct 7, 2026
18 checks passed
@bb7133
bb7133 deleted the perf/fastpath-s2c-response branch October 7, 2026 16:08
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