Skip to content

Add ApiConfig::validateJson to skip WebsocketMessageParser's DOM validation pass - #158

Merged
TuxedoFish merged 1 commit into
mainfrom
perf/websocket-parser-validate-json-toggle
Sep 10, 2026
Merged

Add ApiConfig::validateJson to skip WebsocketMessageParser's DOM validation pass#158
TuxedoFish merged 1 commit into
mainfrom
perf/websocket-parser-validate-json-toggle

Conversation

@TuxedoFish

Copy link
Copy Markdown
Owner

Summary

Test plan

  • ctest (29/29 passing, including websocket_parser_test)
  • Latency comparison against hyperliquid-md-benchmark (results in PR comment)

🤖 Generated with Claude Code

https://claude.ai/code/session_018Le73N2EZjGLsCqmCScAse

…dation pass

crack() runs a full simdjson DOM parse ahead of its on-demand parse purely to
guarantee malformed input is rejected as a catchable error rather than
hitting an internal simdjson ondemand assertion (issue #109). That's a real
cost on every non-fast-pathed message. Set validateJson=false once the feed
is trusted to skip it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Le73N2EZjGLsCqmCScAse
@TuxedoFish

Copy link
Copy Markdown
Owner Author

Latency impact

Measured with hyperliquid-md-benchmark — its replay harness times WebsocketMessageParser::crack() end-to-end on real captured mainnet frames. Pointed its FetchContent at this branch, added a [validateJson=1] CLI arg to bench_cpp that sets ApiConfig::validateJson before constructing the parser, then ran both channels 3x each with validateJson on vs off.

channel validateJson n mean (ns) p50 p90 p99 p99.9
l2Book 1 (default) 12,600 6535 5569 9089 9884 16315
l2Book 0 12,600 6476 5570 9112 10003 16541
bbo 1 (default) 20,000 (x3) 844–858 779–822 853–1039 1320–1654 3317–4899
bbo 0 20,000 (x3) 475–549 460–471 488–888 745–1037 1127–1594
  • l2Book: no real difference — those messages hit crackL2BookFast and return before validateStructure is ever reached, so this flag doesn't touch that path.
  • bbo (and every other channel without a fast path — trades, orderUpdates, userFills, allMids, etc.): consistent ~35-45% reduction in mean/p50/p90 across all three repeated runs.

levelsSeen output matched exactly between the two settings on the same captured data, confirming no functional regression — this is purely the cost of the extra DOM pass.

@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.29%. Comparing base (cc645fd) to head (e3e82a1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #158   +/-   ##
=======================================
  Coverage   70.28%   70.29%           
=======================================
  Files          54       54           
  Lines        8898     8900    +2     
  Branches      539      539           
=======================================
+ Hits         6254     6256    +2     
  Misses       2639     2639           
  Partials        5        5           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions Bot added the ready for review CI passed; ready to be reviewed label Sep 10, 2026
@TuxedoFish
TuxedoFish merged commit f67cd50 into main Sep 10, 2026
12 checks passed
@TuxedoFish
TuxedoFish deleted the perf/websocket-parser-validate-json-toggle branch September 10, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review CI passed; ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant