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
Small perf + testing-coverage items bundled for a single PR.
Item 1 — import asyncio inside AsyncTransport.request hot path
A sys.modules lookup per async request. Negligible but in the per-request hot path and pointless since the module is already imported by KalshiAuth.sign_request_async.
Location: kalshi/_base_client.py:374.
Fix: Move import asyncio to the module's top-level imports.
Item 2 — MessageQueue._size maintained per put/get is redundant with len(deque)
Overflow check uses len(self._buffer) (O(1)), but _size is incremented/decremented on every put and popleft purely so qsize() excludes the single sentinel. Two extra int ops per message on the WS hot path with no functional gain over len(self._buffer) - (1 if self._closed else 0).
Fix: Drop _size and compute qsize() from len(self._buffer) minus a sentinel adjustment when _closed.
Item 3 — No behavioural test or bench for http2=True multiplexing
The advertised h2 multiplexing benefit (#233) is never exercised end-to-end. A regression that silently disables ALPN h2 negotiation, or that mishandles concurrent requests over a single h2 connection, would land without any test failing.
Fix: Add an integration test that hits the demo endpoint with http2=True and asserts response.http_version == "HTTP/2" on a concurrent gather; add a bench variant of bench_request_hot_path.py parameterized on http2.
Item 4 — No bench for high-level Orderbook iterator or DataFrame conversion paths
Both existing orderbook benches stop at the in-place mutation and never measure the mgr.get(ticker) / to_orderbook() materialization that high-level consumers pay. DataFrame conversion (Page.to_dataframe on large pages) and large-list model_validate are completely unbenched.
Fix: Add a bench that drives _OrderbookIterator.__anext__ end-to-end, and a bench_page_to_dataframe.py that times a 1000-item Page → DataFrame conversion.
Activity