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
_apply_delta_inplace invalidates the cached Orderbook view even when delta=0 (no-op mutation) #347
The existing-level branch of _apply_delta_inplace unconditionally calls state.invalidate() whenever the price key already exists, even when delta == Decimal(0) (no-op delta) or when new_qty == existing_qty. For a high-frequency book the next subscribe_book iterator read then pays the O(n log n) sort + 2N OrderbookLevel validations rebuild that #244 was introduced to avoid.
The wire usually doesn't carry delta=0 frames, but OrderbookDeltaPayload.delta is a FixedPointCount with no >0 constraint, and rounding-induced redundant frames can produce the thrash. A single equality check would skip the wasted rebuild.
Evidence
kalshi/ws/orderbook.py:185-196:
ifexisting_qtyisnotNone:
new_qty=existing_qty+deltaifnew_qty<=0:
dellevels[price]
else:
levels[price] =new_qty# #244: a side mutated; drop the cached Orderbook view so# the next `to_orderbook`/`get` rebuilds with the new side.state.invalidate()
elifdelta>0:
levels[price] =deltastate.invalidate()
Activity
perf(ws): orderbook materialization + apply_snapshot single-copy + ze…