Repository navigation
Description
Group B of the serve-path hot-path audit (siblings: #1788 accept path; doc drift: #1787). Everything below runs inline on the stream task between StreamRequest decode and the first ChunkData, so each item is a direct TTFB term — and until #1788 item 1 lands, each also stalls every sibling stream on the connection.
1. Capability persist is an inline fsync with no dedup
crates/node/src/handlers/client/mod.rs:1390-1393 → channel_store.rs:886-922 (put_capability, Durability::Immediate). Every request carrying a capability ext awaits a spawn_blocking redb commit (fsync) before the StreamResponse is signed. There is no already-persisted short-circuit (unlike register_lane, which dedups at mod.rs:1422), and the write is idempotent, so repeat capability sends re-fsync. The commit also queues on the single lanes.redb writer behind the periodic voucher flush and other durable writes.
Fix: dedup against the in-memory lane/capability record, and make the write buffered with the pre-redemption flush_store_durable (payment_settlement.rs:1276-1291) as the durability floor — the same model the lane store itself uses per ADR 003 §Off-chain voucher state persistence.
Improves: removes millisecond-scale disk latency (plus writer-queue wait) from TTFB for every capability-bearing open; repeats become free.
Leaving as-is limits: the TTFB floor for paying clients includes a disk commit; under node-wide payment activity, opens queue behind the lane flush on one redb writer, so open latency grows with unrelated load; any disk stall translates directly into TTFB spikes for new streams.
2. Three secp256k1 operations on the shared task, with no capability-verification cache
Two ecrecovers — client binding at dispatch.rs:144-149 (bind_sig.rs:153-161) and capability owner sig at mod.rs:1346-1359 (capability.rs:112-131) — plus one EIP-712 sign of the StreamResponse at wire.rs:65-80 (stream_sig.rs:149-156). Together ~250–500 µs of serialized CPU per open. The binding is cached per connection but the capability is re-recovered on every request that carries it.
Fix: offload to a worker pool (or rely on #1788 item 1), and cache capability verification keyed by signature bytes.
Improves: takes the crypto off the accept task; repeated capability sends skip ecrecover entirely.
Leaving as-is limits: request throughput per connection is CPU-bounded by serialized signature work; at high open rates the accept task saturates a core and every stream on the connection queues behind it. The sign itself is protocol-mandatory (ADR 005 — slash_sig on every StreamResponse), so the only lever is where it runs.
3. refresh_lane_metrics on the first-time-lane open path
mod.rs:1443 → mod.rs:1767-1773: a global tokio::Mutex plus DashMap::len() (which walks every shard) awaited before first byte whenever a new lane registers.
Fix: maintain the gauge as an atomic counter bumped at register/forget, or refresh on a timer.
Improves: new-lane opens stop serializing on a process-wide mutex.
Leaving as-is limits: lane registration is exactly what grows with adoption (more clients, more pools); at scale, concurrent new-lane opens contend on one mutex and the len() walk cost grows with total lane count — a per-customer-growth tax on first-request latency.
4. register_lane wraps a buffered map insert in spawn_blocking(...).await
mod.rs:1429-1431. The store call is an in-memory insert since the store became buffered (channel_store.rs:679-691); the thread-pool round trip is pure added latency (the stale "synchronous fsync" comment there is part of #1787).
Fix: call it inline.
Improves: removes a blocking-pool hop from the open path.
Leaving as-is limits: adds latency per new lane and puts needless pressure on the blocking pool, which is shared with real fsyncs — pressure there feeds back into item 1 and the flush task.
5. evicted is the one mutex inside the per-request deny check
crates/cache/src/engine.rs:217, read via refuses at :1945-1951 on every request — and on the miss path once per 16 KiB leaf (see the miss/fill sibling issue). Its siblings (denied, chain_denied) are already ArcSwap for exactly this reason (content_deny.rs:105-112).
Fix: ArcSwap<HashSet<Hash>> with RMW updates (evictions are rare).
Improves: the admission deny check becomes fully lock-free.
Leaving as-is limits: a global mutex acquisition per request whose contention grows with request rate × miss depth, and which couples the serve path to eviction and probe-hold activity.
6. Faulting origins are never memoized in the presence probe
engine.rs:1409 (path: dispatch.rs:246-270). Not-found results get a negative TTL; faults do not, so a broken backend is re-probed on every request for its namespace.
Fix: a short fault TTL distinct from the not-found TTL.
Improves: bounds backend probing under origin failure.
Leaving as-is limits: one faulting origin collapses TTFB for its entire namespace to the origin's fault latency (a full backend round trip per request) and hammers the failing backend — an availability incident amplifier.
7. Serial admission awaits and split has/inspect store hops
dispatch.rs:448,893 and the surrounding sequential awaits (deny checks, pool lookup, cache presence).
Fix: join the independent checks; fold has+inspect into one store-actor call.
Improves: shaves fixed round trips off the pre-byte sequence.
Leaving as-is limits: a constant additive latency per open — small individually, but it sits on every request and matters once the items above stop dominating.
Activity
perf(node): run capability ecrecover outside the verify cache lock (#…
perf(node): buffer and dedup capability persistence onto the lane flu…
perf(node): cache capability owner-recovery so repeat sends skip ecre…
perf(node): atomic lane-count gauge and inline lane registration (#1789…
perf(cache): make evicted set lock-free via ArcSwap (#1789 item 5)
perf(cache): memoize origin-presence faults under a distinct short TTL (
perf(node): overlap the origin presence probe and pool-view read on s…
perf(cache,node): fold serve presence+size into one store contact (#1789
perf(node): run capability ecrecover outside the verify cache lock (#…
fix(cache,node): address the review of the TTFB open-path work (#1789)
perf(node,cache): reduce TTFB on the cdn/client stream-open path (#1789…
Merge origin/main into feat/1841-per-signer-floor-isolation