Skip to content

bench(clob): read-path contention — Arc<Mutex<Book>> vs ArcSwap#2

Open
psyto wants to merge 2 commits into
mainfrom
claude/clob-read-bench
Open

bench(clob): read-path contention — Arc<Mutex<Book>> vs ArcSwap#2
psyto wants to merge 2 commits into
mainfrom
claude/clob-read-bench

Conversation

@psyto

@psyto psyto commented Jul 9, 2026

Copy link
Copy Markdown
Owner

A runnable benchmark of the openhl CLOB read path: the read_best_bid precompile locks the shared Arc<Mutex<Book>> that the block-builder also locks to apply orders. Measures what a reader feels while a writer is busy.

Result (this machine, writer flat-out, 200k reads, depth 500/side)

p50 p99 p99.9 max
Arc<Mutex<Book>> 41ns 330µs 6.5ms ~55ms
ArcSwap<Book> 41ns 42ns 166ns ~15µs

Same p50 — the mean/median hide the contention cliff entirely. Under a busy writer the Mutex reader blocks for milliseconds; ArcSwap stays flat. Tradeoff: ArcSwap clones the whole Book per published version (cost moves to the write side).

Honest scope: the writer runs flat-out, so this shows the shape of the cliff (a stress upper bound), not a production p99 — and p99/p99.9 are the robust signal; max can include OS scheduling noise.

Run it: cargo bench -p rdk-clob --bench read_contention

Adds arc-swap as a dev-dependency; no library change.

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

🤖 Generated with Claude Code

psyto and others added 2 commits July 8, 2026 10:31
Lead with the sharp, star-proven hook (openhl = a Hyperliquid-shape perp
DEX as its own Reth L1, 590 tests, read-and-run) instead of the abstract
'DeFi Kit' framing. openhl is the flagship reference implementation,
princeps the second, the crates/ kit the shared layer behind them —
positioned the way Reth ships (one repo, reusable crates, binaries on top).
Content (structure/layer rules/stack/builds) unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Reproduces the openhl read path (read_best_bid precompile locks the shared
Arc<Mutex<Book>> the block-builder also locks) and measures reader tail
latency under a concurrent writer. On this machine: Mutex read p99 ~330us /
p99.9 ~6.5ms / max ~55ms, vs ArcSwap p99 ~42ns — same p50 (~41ns), so the
mean/median hides the contention cliff entirely. Writer-side tradeoff: ArcSwap
clones the whole Book per published version. Run: cargo bench -p rdk-clob
--bench read_contention.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant