Engine architecture and benchmarks
Docs

Engine architecture and benchmarks

A Rust service that turns Hyperliquid's feeds into decisions in microseconds, and the measured numbers behind that claim.

The hot path

One task owns the whole pipeline, so the hot path takes no locks: frame in, decisions out. Everything else (the API, the keeper, the cross-check, the Kinetiq rate reader) talks to it through channels and reads a snapshot it publishes four times a second. Built on tokio, tokio-tungstenite, axum and alloy; frames are parsed with sonic-rs into borrowed views, never copied.

WebSocketHyperliquid feeds, ping 20 s, stall after 10 s, backoff reconnect
Parsesonic-rs, borrowed strings, no copies
Market statefields: mark, mid, funding, books, trades, positions
Indexonly strategies reading the field that moved
Deciderising edge = one trigger
Keeperfreshness gates, simulate, send, record
Frame to decision. The service, the replay tests and the benches all run this one path.

Dependency and threshold index

Each condition is split into atoms (single comparisons) joined by a small boolean formula. Atoms of the shape value op constant and value crosses constant sit in a per-value index sorted by threshold. When HYPE's mid moves from old to new, only the atoms whose threshold lies between the two can change, and only those are touched. Other comparisons (like mark minus oracle over oracle) re-run in the VM whenever one of their values changes.

HYPE.mid thresholds, sorted33.133.634.034.434.735.035.235.535.936.336.837.4old 34.2new 35.64 of 12 comparisons flip and are touched; the other 8 are never looked at
An update touches the thresholds it crossed, not the strategies that exist.

A strategy is re-evaluated only when one of its atoms changed state, a for timer came due, or a cross pulse ended. Identical atoms across strategies are stored once.

One set of semantics

  • An event is one market update: a batch of values at one time.
  • A strategy is false whenever any of its atoms errors (an unknown value, a math error).
  • crosses is true only in the event where the value moved across the threshold.
  • for D holds once the inner condition has been true since s and the event time, rounded up to the second, is at least s plus D.
  • A decision is a rising edge of the value: at most one per trigger.

How it is tested

TestWhat it proves
Reference interpreter + property testA slow interpreter that walks the syntax tree and re-evaluates every strategy on every event shares nothing with the engine but the arithmetic. 3,000 random cases of random strategies and market sequences must give exactly the same decisions, and every decision must pass the on-chain VM with the values a keeper would submit.
Replay of recorded mainnet sessionsA WebSocket session captured from the live Hyperliquid feed: every frame parses, the engine is deterministic, and it agrees with the reference interpreter on real market data.
Shared VM vectorsOne vector file runs through the Rust VM and the Solidity VM; both must produce the same result for every case.
Foundry suitesUnit, fuzz and invariant tests for the registry, limits, bonding and slashing, plus mainnet fork tests.

Measured numbers

Every number below is copied from the published benchmark file, unchanged.

Measured 2026-11-29. one CPU core, release build (cargo --release), x86-64 Linux.

Criterion

BenchMedianWhat it measures
parse/activeAssetCtx819 nsparse one live activeAssetCtx frame
parse/allMids224.99 µsparse one live allMids frame (every listed market, about 25 KB)
update/100048 nsone HYPE mid move of 0.01% against 1,000 loaded strategies
update/10000125 nssame, 10,000 strategies
update/1000001.003 µssame, 100,000 strategies
frame/1000028.305 µsa full HYPE activeAssetCtx frame (mark, mid, oracle, funding, oi) parsed and evaluated, 10,000 strategies
frame/1000001.604 mssame, 100,000 strategies; the 10% general expressions on HYPE rerun on every mark move

Replay loadtest

StrategiesFramesp50p90p99maxFrames/s
10,00010,4801.7 µs11.18 µs250.1 µs720.81 µs127,718
100,00010,4802.08 µs180.14 µs873.91 µs11590.29 µs17,455
StrategiesChannelFramesp50p99
10,000activeAssetCtx5,2801.78 µs30.73 µs
10,000allMids140251.41 µs380.56 µs
10,000l2Book1607.49 µs9.67 µs
10,000other2800.26 µs3.77 µs
10,000trades4,3001.52 µs33.8 µs
10,000userFills3202.1 µs27.64 µs
100,000activeAssetCtx5,2802.2 µs947.22 µs
100,000allMids140300.44 µs425.08 µs
100,000l2Book16010.42 µs14.72 µs
100,000other2800.3 µs7.4 µs
100,000trades4,3001.6 µs34.12 µs
100,000userFills3203.49 µs29.91 µs

With stocks: the larger universe

573 perps loaded: Hyperliquid core plus every HIP-3 dex (178 live markets on xyz, para, io, mkts; 128 tracking a US listing). fixtures/session-2.jsonl: 1,016 frames recorded from wss://api.hyperliquid.xyz/ws on Sunday 2026-11-29 with the US market closed: core allMids, allMids of each HIP-3 dex, activeAssetCtx and trades of HYPE, BTC, ETH, xyz:NVDA, xyz:TSLA, xyz:AAPL, xyz:SP500, xyz:GOLD, l2Book of HYPE and xyz:NVDA.

ReplayStrategiesFramesp50p90p99Frames/s
stocks session10,00020,3201.62 µs8.538 µs64.101 µs20,328
stocks session100,00020,3201.939 µs53.674 µs1571.762 µs3,379
original session, same moment10,00010,4801.821 µs14.472 µs298.836 µs24,199
original session, same moment100,00010,4802.876 µs471.45 µs4986.735 µs2,987

Same core, release build, but the machine was shared with other builds at the time (load average about 30), so the tail is noisier than the quiet-machine table above. The original session was rerun at the same moment for a fair comparison. Command: scriptcore-engine loadtest N 20 fixtures/session-2.jsonl.

Method

Criterion benches (cargo bench --bench engine) for the evaluator alone; the loadtest (scriptcore-engine loadtest N 20) replays a recorded mainnet WebSocket session (524 frames captured from wss://api.hyperliquid.xyz/ws: activeAssetCtx, trades, l2Book, allMids, userFills) 20 times through the same parse -> state -> evaluator path the service runs, with N strategies loaded around the session's own HYPE price: 55% thresholds, 20% crosses, 15% threshold and funding, 10% general expressions (mark minus oracle). Latency is per frame, from frame text to decisions.

  • strategyChecksPerSec: frames per second times strategies loaded: every frame answers the condition of every loaded strategy, most of them through the index without running
  • atomsEvaluatedPerSec: comparisons actually re-evaluated per second

Reproduce them

The engine's criterion suite and the replay loadtest are the same code that produced the tables above.

cargo bench --bench engine                 # parse, update/N, frame/N
scriptcore-engine loadtest 100000 20       # replay the recorded session 20 times, 100,000 strategies
scriptcore-engine loadtest 100000 20 fixtures/session-2.jsonl   # same, the session with HIP-3 stocks and every dex
cargo test --release                       # property test, replay, shared vectors

Live metrics

The running engine reports its own live p50 and p99 from frame read off the socket to decision at /api/engine/stats, and a Prometheus page at /api/engine/metrics with frames by channel, decisions, fires sent, failed and refused, RPC errors by chain, WebSocket lag and reconnects, queue depth, strategies and atoms loaded, the cross-check gap, and the ingest-to-decision histogram.