bench: add live submit path benchmark

This commit is contained in:
floor-licker
2026-06-23 09:14:07 -04:00
parent fd8a2ebdb3
commit 71e1566c8f
3 changed files with 563 additions and 0 deletions
+2
View File
@@ -76,6 +76,8 @@ Real-world Polymarket API latency broken down by request phase:
Run the WS hot-path benchmark locally with `cargo bench --bench ws_hot_path`.
**Live submit-path comparison:** run `cargo run --release --example live_submit_path_benchmark --features official-client-benchmark` with `POLYMARKET_PRIVATE_KEY` set. The setup phase derives API credentials by default; set `POLYMARKET_BENCH_DERIVE_API_CREDS=false` to use `POLYMARKET_API_KEY`, `POLYMARKET_API_SECRET`/`POLYMARKET_SECRET`, and `POLYMARKET_API_PASSPHRASE`/`POLYMARKET_PASSPHRASE` from the environment instead. By default this only runs safe authenticated live reads against Polymarket for `polyfill-rs` and `rs-clob-client-v2`. Actual live order posting is intentionally disabled unless `POLYMARKET_BENCH_LIVE_POST_ORDER=1` is set; if `POLYMARKET_BENCH_TOKEN_ID` is omitted, the benchmark selects an active token with midpoint at least `POLYMARKET_BENCH_MIN_MIDPOINT` and resolves that token's tick-size/neg-risk config before timing. Successful orders are canceled immediately after timing is recorded.
**Parsing paths:** `polyfill-rs` keeps two parsing layers on purpose. The allocation-sensitive WS `book` path uses `WsBookUpdateProcessor` in `src/ws_hot_path.rs`, which walks a reusable `simd-json` tape and applies fixed-point book levels directly. The generic stream parser in `src/decode.rs` is an ergonomic compatibility path: it parses through `serde_json::Value` so it can tolerate batches, unknown event types, and mixed message shapes. Likewise, several generic numeric/decimal deserializers in `src/decode.rs` accept string-or-number API fields through `serde_json::Value`; they are not the zero-allocation hot path.
**WebSocket snapshot ordering:** Polymarket `book` messages expose a millisecond `timestamp` and optional `hash`, but no monotonic server sequence/version. The book applier treats newer timestamps as newer, rejects older timestamps, suppresses exact same-timestamp/same-hash duplicates, and accepts same-timestamp/different-hash snapshots in websocket arrival order. The hash distinguishes duplicate vs distinct state; it is not a logical ordering key.