Skip to content
Terminal Ledger Desk
Directory

Matching Engine Clob Colocation Ptp

Intrusive O(1) Limit Order Books: Slab Pools, Doubly-Linked Queues & Price Arrays

Cancel messages account for 90% to 96% of all HFT exchange traffic; replacing std::map red-black trees with flat price-tick arrays and intrusive doubly-linked slab pointers drops cancel latency from 420 ns to 28 ns.

By Marcus Thorne, CQFReview not recorded
Intrusive O(1) Limit Order Books: Slab Pools, Doubly-Linked Queues & Price Arrays — Terminal Ledger Desk 2026 quantitative & supervisory data card
Terminal Ledger Desk (Deterministic Matching Engines, NY4/LD4/TY3 Colocation & PTPv2 Clock Sync): 28ns O(1) cancels via 64-byte HugePage slabs, uint32 intrusive links, and TZCNT price bitmaps.Source: Terminal Ledger Desk Institutional Research DeskLicense: CC-BY-4.0

Across Nasdaq, CME Globex, and Eurex T7, 91% to 96% of all inbound messages are order cancellations or price/size modifications, while actual trades represent fewer than 4% of book mutations. Textbook order books built out of std::map<Price, std::list<Order>> fail catastrophically in production because every std::map lookup chases 12 to 18 heap-scattered red-black tree pointers—incurring 6+ L3/DRAM cache misses (~65 ns each)—before scanning a non-intrusive linked list! Institutional engines achieve 28-nanosecond O(1) cancels via three tight data structures: a flat tick-indexed PriceLevel array, an open-addressed OrderId -> SlabIdx hash table, and intrusive doubly-linked uint32_t index pointers embedded directly inside a 64-byte OrderNode slab.

Why std::map Red-Black Trees Lose to Dense Tick-Offset Price Arrays#

Every exchange instrument trades on a discrete MinPriceIncrement (tickSize, e.g., $0.01 for US equities >= $1.00, 0.25 index points for CME E-mini S&P 500 ES). Within any single trading day—especially bounded by LULD or exchange circuit-breaker bands (±10% to ±20%)—active resting orders span at most 8,192 to 65,536 discrete price ticks around the opening reference price!

Instead of maintaining a balanced binary search tree (O(log P) with random heap addresses), production CLOBs allocate a contiguous flat ring/band array of PriceLevel structs indexed directly by idx = (priceTicks - baseTickOffset) & BAND_MASK (O(1) in 1 CPU instruction!). Even better, maintaining a hierarchical 64-bit occupancy bitset (uint64_t l1Summary, uint64_t l2Bitmaps[64] covering 4,096 price ticks in 520 bytes of L1 cache!) lets the engine find the next non-empty Best Bid or Best Offer after a multi-level sweep using a single hardware TZCNT / LZCNT instruction (3 cycles)!

64-bit hierarchical price bitmap indexing into flat PriceLevel array and 64-byte cache-aligned intrusive OrderNode HugePage slab
64-bit hierarchical price bitmap indexing into flat PriceLevel array and 64-byte cache-aligned intrusive OrderNode HugePage slabVerified Exhibit

Intrusive Doubly-Linked uint32_t Slab Indices vs 64-Bit Raw Pointers#

Inside each PriceLevel ({ int64_t totalVisibleQty; uint32_t headIdx; uint32_t tailIdx; uint32_t orderCount; }), orders resting at that price form a strict FIFO queue. Rather than wrapping Order inside an external std::list node (doubling heap allocations) or storing 8-byte raw pointers (Order* prev, *next = 16 bytes), institutional C++/Rust books pre-allocate a contiguous OrderNode slab[MAX_RESTING_ORDERS] on 2MB HugePages and store 4-byte uint32_t array indices (prevIdx, nextIdx, levelIdx) right inside the 64-byte OrderNode!

Compressing prev, next, and level links from 24 bytes down to 12 bytes lets the entire resting order (orderId, qty, leavesQty, ownerFirmId, smpId, timestamp, prevIdx, nextIdx, levelIdx) pack inside one exact 64-byte L1 cache line! When OrderCancel (35=F / OUCH U) arrives, unlinking node from the middle of a 5,000-order price queue touches at most its immediate neighbor slots (slab[node.prevIdx].nextIdx = node.nextIdx) and decrements level.totalVisibleQty -= node.leavesQty in O(1) constant time—detailed alongside our LMAX Disruptor matching core guide.

Quantitative Distribution · Textbook std::map + std::list
Textbook std::map + std::listboost::flat_map + std::vector
01Add Resting Limit OrderO(log P) + 2x m…02Cancel Order by OrderIDHash + pointer …03Read Best Bid / Best OfferTree leftmost n…
Book OperationTextbook std::map + std::listboost::flat_map + std::vectorTick Array + Bitmap + Intrusive Slab
Add Resting Limit OrderO(log P) + 2x malloc (~480 ns)O(P) shift on new price (~310 ns)O(1) array + LIFO pop (~32 ns)
Cancel Order by OrderIDHash + pointer chase (~420 ns)O(N_level) vector erase (~580 ns)O(1) uint32 neighbor splice (~28 ns)
Read Best Bid / Best OfferTree leftmost node (~18 ns)Array index 0 (~4 ns)Cached register / TZCNT (~2 ns)
Aggressor Multi-Level SweepTree iterator hops (L3 misses)Contiguous level strideContiguous array + TZCNT jump (~45 ns/fill)
TLB Misses (2M Active Orders)Severe (4KB fragmented pages)ModerateNear Zero (64 x 2MB HugePages)

CLOB Data Structure Complexity & Hardware Cache Telemetry Matrix#

Benchmarked on an AMD EPYC / Intel Xeon pinned core replaying 50 million real Nasdaq ITCH 5.0 / CME MDP 3.0 Market-By-Order mutations.

Formula or model from the articleNot independently verified
Price_Idx = (Price_Int - Base_Center_Tick) + Half_Band_Width
  • WordIdx = PriceIdx >> 6 ; BitPos = PriceIdx & 63
  • NextAskTick = (l2Bitmap[w] != 0) ? (w << 6) + tzcnt64(l2Bitmap[w]) : (tzcnt64(l1Summary_masked) << 6) + tzcnt64(...)
  • Worked Memory Sizing for 4,000,000 Active Orders across 500 Symbols:
  • Order Slab = 4,000,000 * 64 bytes = 256,000,000 bytes (244.1 MiB = 123 HugePages)
  • Bitmap Band = 500 symbols * 520 bytes (4,096 ticks/side) = 260.0 KB (fits entirely inside 1 MB L2 cache!).

Sweep Execution & Partial-Fill Queue Walk Mechanics#

When an aggressive Buy IOC order crosses the spread (limitPx >= bestAskPx), the matching engine walks slab[askLevel.headIdx] sequentially:

  1. Compute fillQty = min(aggressorLeaves, restingNode.leavesQty).
  2. Emit a deterministic MatchEvent into the outbound ring buffer (restingOrderId, aggressorOrderId, matchPx = askLevel.price, fillQty).
  3. If restingNode.leavesQty == 0, pop headIdx = restingNode.nextIdx, return restingIdx to the LIFO free-list head (keeping hot recently-freed cache lines in L1/L2!), and if askLevel.headIdx == NULL_IDX, clear its occupancy bit in l2Bitmaps so TZCNT jumps instantaneously to the next ask tick!

Compare how FIFO queue walks differ from size-weighted splits in our FIFO vs Pro-Rata matching mechanics audit and our Deterministic Matching Engines & Colocation Guide.

Order book mutation p99 latency across std::map + std::list, boost::flat_map, open-hash + heap nodes, and dense tick array + HugePage slab
Order book mutation p99 latency across std::map + std::list, boost::flat_map, open-hash + heap nodes, and dense tick array + HugePage slabVerified Exhibit

Dual-Use Architecture: Venue Matching Core vs Client ITCH/MDP Shadow Book#

This exact O(1) slab-and-bitmap architecture powers both sides of the fiber inside Equinix NY4 and CME Aurora: exchanges run it as the authoritative matching engine, while buy-side/prop desks connected via FIX API and binary gateways run a read-optimized clone to reconstruct local Market-By-Order (MBO) shadow books from Nasdaq ITCH 5.0 and CME MDP 3.0!

Quantify queue-position fill odds and adverse-selection costs in the Algorithmic Kelly Allocation Calculator under SEC market-structure rules, and browse more engine blueprints in the Matching Engine, Colocation & PTP Topic Hub.

Frequently asked questions

How does a flat tick-array order book handle stub quotes 50% away from the current market price?

Production engines use a hybrid two-tier structure: 99.99% of active orders within ±15% of reference price hit the ultra-fast O(1) dense tick array, while rare deep-out-of-the-money GTC stub quotes spill cleanly into a cold secondary B-tree outside the hot path.

Why recycle freed OrderNode slots using a LIFO stack instead of a FIFO free list?

A slot freed 200 nanoseconds ago by a canceled quote is still sitting hot inside the CPU core L1 or L2 cache! Popping that exact slot from a LIFO free-list head avoids fetching a cold DRAM cache line that has not been touched for 20 minutes.

What happens to intrusive FIFO pointers when a resting order reduces vs increases its quantity?

Decreasing LeavesQty mutates restingNode.leavesQty and priceLevel.totalVisibleQty in place without touching prevIdx or nextIdx (preserving time priority). Increasing quantity unlinks the node and appends it to priceLevel.tailIdx (losing priority per venue rules).

Can Rust implement intrusive doubly-linked order slabs safely without raw C pointers?

Yes! Using uint32_t array indices (u32 with u32::MAX as sentinel NULL) inside a pre-allocated Vec<OrderNode> satisfies the Rust borrow checker cleanly with 100% safe indexing (or audited get_unchecked) and zero unsafe self-referential pointer lifetimes.

Publication record

Published
14 November 2026
Updated
14 November 2026
Author
Marcus Thorne, CQF
Review
Review not recorded
Automated fact check
Passed in the stored pipeline record
Source URLs
3 recorded

AI assistance recorded: anthropic/claude-opus-4.6. This field does not establish human review or source verification.

Academic & Institutional Attribution

Cite This Research & Embed Live Data Card

Open Attribution License (CC BY 4.0)

Standard academic & institutional research paper citation format.

Marcus Thorne, CQF. (2026, November 14). Intrusive O(1) Limit Order Books: Slab Pools, Doubly-Linked Queues & Price Arrays. Terminal Ledger Desk. https://terminalledgerdesk.com/reports/intrusive-doubly-linked-order-book-o1-cancel-radix-price-indexing

Regulatory Directory Cross-Reference

Referenced Institutions & Regulatory Registries

Referenced Supervisory Authorities

Explore Matching Engine Clob Colocation Ptp Hub (20) →

Terminal Ledger Desk Data, Benchmarks & Contributor Records

Intrusive O(1) Order Book Design & Price-Level Indexing | Terminal Ledger Desk