You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SequenceTracker.track is async but only awaits on the rare gap path — every frame pays coroutine overhead #330
SequenceTracker.track is declared async def solely so it can await self._on_gap(gap) in the gap and reset branches. The happy path (seq == expected, the case on every legitimate sequenced frame) does no I/O and no awaiting, yet _process_frame pays the full async-call overhead per frame: coroutine object allocation, __await__ step, frame teardown.
orderbook_delta and order_group_updates run at thousands of frames per second per subscription on a busy strategy. The previous perf wave (#245, #271) eliminated per-frame Task / shield / contextvars allocations exactly because they showed up in profiles; the per-frame track coroutine remains.
Evidence
kalshi/ws/sequence.py:49-118 — async signature, but the four early-return branches that fire on every frame do no awaiting
Split into a sync track_sync(sid, seq, channel) -> tuple[bool, SequenceGap | None] that does the bookkeeping and returns the gap object (or None) without awaiting. The hot-path caller becomes:
Keep the async track as a thin backwards-compat wrapper that calls track_sync then awaits the callback, for any external users and for the existing tests in tests/ws/test_dispatch.py / test_integration.py. Verify with scripts/bench_ws_recv.py.
Activity
polish(ws): seq sync hot path + orphan correlation + reconnect exc_in…