Skip to content

perf(bench): custom SPSC report transport (cpp-fastchan) — competition bench +22–32%#35

Merged
geseq merged 1 commit into
mainfrom
perf/fast-transport
Jun 29, 2026
Merged

perf(bench): custom SPSC report transport (cpp-fastchan) — competition bench +22–32%#35
geseq merged 1 commit into
mainfrom
perf/fast-transport

Conversation

@geseq

@geseq geseq commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Backs the matching-engine-benchmark report queue with geseq/cpp-fastchan instead of the harness's default boost::lockfree::spsc_queue, via the API's engine_get_transport() escape hatch. Adapter-only — the engine is untouched.

Why

The competition harness is transport-bound: the engine (single-thread replay) runs ~28–37 M msgs/s, but the end-to-end harness caps at ~14 because every report crosses a SP/SC queue to the drainer thread, and the default boost::lockfree::spsc_queue does a release-store per push. Profiling + an assert-on/off A/B confirmed the queue, not the book, is the limiter. The harness API explicitly permits an engine to substitute its own transport ("e.g. a proprietary lock-free ring").

What

  • bench/cpp_orderbook_adapter.cpp: export engine_get_transport() backed by fastchan::SPSC<me_report_t, 1<<20> (create/push/drain/flush/destroy).
  • CMakeLists.txt: CPM dep geseq/cpp-fastchan, bracketed with an ENABLE_TESTING save/restore so fastchan's own (shared-named) test suite doesn't join our ctest.
  • bench/build.sh: fastchan include path.

Results — 5-way SPSC bake-off (same engine, same-run best-of-12)

scenario boost (default) cpp-fastchan moodycamel rigtorp hand-rolled
static 14.2 18.3 12.4 13.7 17.0
normal 14.0 18.5 13.3 13.4 17.1
swing-25 13.7 17.6 13.6 13.4 17.4
swing-40 14.4 17.6 12.3 12.7 14.2
flash-crash 13.9 17.0 13.6 13.0 16.7

cpp-fastchan wins outright: +22–32% over the boost default across all 5 scenarios (M msgs/s), beating moodycamel, rigtorp, and a hand-rolled batched ring. This is the lever that actually moves the competition number — the engine optimizations (already merged) were transport-capped.

Correctness

Byte-identical consensus hash PASS on all 5 scenarios (boost default and cpp-fastchan produce identical trade streams). Verified from a clean from-scratch build. ctest unaffected (fastchan's own tests excluded).

🤖 Generated with Claude Code
https://claude.ai/code/session_0196EKKWudtsg3gButufhDxz

Export engine_get_transport() backing the harness report queue with
geseq/cpp-fastchan instead of the harness default boost::lockfree::spsc_queue.
The matching-engine-benchmark is transport-bound on the report queue (the
engine is ~2x faster than the default queue can drain), so a faster SP/SC
channel lifts the end-to-end ceiling. The harness API explicitly permits an
engine to substitute its own transport.

cpp-fastchan won a 5-way same-run SPSC bake-off (boost default / moodycamel /
rigtorp / a hand-rolled batched ring / cpp-fastchan): +22-32% over the boost
default across all 5 scenarios, best-of-N. Adapter-only; engine untouched.

- bench/cpp_orderbook_adapter.cpp: engine_get_transport() over fastchan::SPSC<me_report_t>.
- CMakeLists.txt: CPM dep geseq/cpp-fastchan; bracketed with ENABLE_TESTING save/restore
  so fastchan's own (shared-named) test suite doesn't join our ctest.
- bench/build.sh: fastchan include path.

Consensus PASS (byte-identical trade streams) on all 5 scenarios.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0196EKKWudtsg3gButufhDxz
@github-actions

Copy link
Copy Markdown

Benchmark PR

Throughput on hosted runners is noisy and not performance-calibrated; treat the numbers as informational only.

Realistic deep-book throughput (W=50000)

Metric PR main change
ops/sec 27,093,749 26,982,827 +0.4%

Matching-engine-benchmark (perf mode)

Harness pinned at 77697a115e76a25a1e2aa886f555d55b87fcf052.

Scenario PR (M msgs/s) main (M msgs/s) change PR correctness
static 8.512 8.411 +1.2% PASS
normal 9.230 9.084 +1.6% PASS
swing-25 9.079 8.625 +5.3% PASS
swing-40 8.584 8.712 -1.5% PASS
flash-crash 8.244 8.614 -4.3% PASS

@geseq geseq merged commit 73b1490 into main Jun 29, 2026
5 checks passed
@geseq geseq deleted the perf/fast-transport branch June 29, 2026 01:58
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