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
WS: pluggable JSON loader/dumper hook (orjson opt-in) for recv/send hot path #209
Every WS frame is parsed via stdlib json.loads(raw) and every outbound subscribe/unsubscribe is serialized via json.dumps(msg). There is no configuration hook to swap in orjson.loads/ujson.loads, and no documentation mentions the option.
stdlib json.loads is roughly 2–3× slower than orjson on real-world Kalshi frames. For a trader streaming orderbook_delta on multiple deep markets at >5–10k msg/s, that gap dominates recv-loop CPU and starves the dispatch coroutine. The dispatcher already takes a pre-parsed dict via pre_validated, so the recv loop is the only critical-path json.loads call site — a single injection point covers the hot path.
Location
kalshi/ws/client.py:253 — data = json.loads(raw) (recv hot path)
kalshi/ws/channels.py:136 — data = json.loads(raw) (subscribe-ack wait)
Use from _process_frame, SubscriptionManager._wait_for_response, and ConnectionManager.send. Mention orjson/ujson in docs/websockets.md performance section with example:
Activity