LIVE SUBMISSIONS — 3 DAYS

Eviscerated by Rust: Overcoming C++'s 58x Standard Library Handicap

Published: April 08, 2026 | Benchmarking & Profiling Rust


The C++ standard library's default containers are a performance disaster. Not a minor inconvenience. Not a "it depends on the workload" caveat. A 58x P99 latency penalty compared to Rust's standard library, on an identical order book workload, with the same seed, same venue, same CPU cores.

This isn't a Rust-is-faster story. It's a story about how std::unordered_map, std::map, and std::list — the containers every C++ textbook teaches, the ones the committee has shipped since 1998 — are so catastrophically bad for modern hardware that a Rust beginner using default containers demolishes a C++ solution without trying. And how we proved it by systematically replacing each C++ container until parity was reached.

The Setup

We run C++ and Rust benchmark challenges at HFT University. Challenge 02 is a multi-symbol order book: 200 symbols, venue interaction, queue position tracking, 500K prefilled orders, P99 latency scored across ~112K timed operations. Real workload patterns — tick-snapped prices, hot/cold symbol distribution, deep FIFO queues.

To make the comparison airtight, we shared everything. The workload generator is a C++ static library with a C API. The Rust benchmark links it via FFI through build.rs — same mt19937_64 RNG, same seed 0xCAFEBABEDEADBEEF, same tick-snapped price generation. We hashed all 612,225 operations from both generators and got identical results:

Setup: 500,000 ops | Timed: 112,225 ops
Setup hash: d04df27a6f2f36db
Timed hash: 50589e9e632ce7d4

Even the venue — the exchange simulator that processes our-order round-trips during the timed phase — is shared C code. Both languages call the same wg_venue_send_order(). Zero wiggle room.

The Damage

Hz2 server, AMD i9-9900K, isolated cores, single iteration:

Solution P99 p50 avg max n
C++ stdlib 302,653 1,581 22,532 439,177 112,225
Rust stdlib 5,177 713 1,026 7,750 112,225

Read that again. Rust's worst-case single operation (7,750 cycles) is better than C++'s median. The C++ standard library doesn't just lose on tail latency — it loses at every single percentile. And both solutions implement the same algorithm: hash map for order lookup, sorted tree for price levels, queue for FIFO ordering.

The difference is entirely in what "hash map," "sorted tree," and "queue" mean in each language's standard library.

The Autopsy: Three Containers, Three Failures

Failure #1: std::unordered_map — The Worst Hash Map In Any Major Language

std::unordered_map is a chained hash table. Each bucket is a linked list of heap-allocated nodes. Every insert() calls operator new. Every find() follows pointers to random heap locations. The nodes are scattered across memory with zero locality guarantee.

This design was defensible in 2003 when the STL was standardized. Cache lines were 32 bytes, L2 was 256KB, and pointer-chasing wasn't a death sentence. In 2026, on a CPU where an L3 cache miss costs 200+ cycles, chaining is architectural malpractice.

Google published Swiss Table in 2017. Open addressing, inline key-value storage, SIMD-accelerated control byte probing. They shipped it as absl::flat_hash_map and it's been battle-tested in production at Google scale for nearly a decade. Rust adopted the same design as its default HashMap (via the hashbrown crate) in 2019. The C++ committee? Still shipping std::unordered_map as the default in 2026. std::flat_hash_map doesn't exist. std::flat_map landed in C++23 as a sorted container, not a hash map.

Every C++ developer writing latency-sensitive code knows to reach for Abseil. But you shouldn't need tribal knowledge to avoid the containers your own language ships.

Failure #2: std::map — A Red-Black Tree In The Age Of B-Trees

std::map allocates one heap node per entry. Each node has three pointers (left, right, parent) plus color bits, the key, and the value. Iteration follows pointers through scattered memory. Even on a workload that barely touches the tree, you're paying the allocation tax on every insert.

Rust's BTreeMap is an actual B-tree — multiple keys packed into each node, excellent cache-line utilization, far fewer allocations. The C++ equivalent exists in Abseil as absl::btree_map, but it's not in the standard. There's no std::btree_map. The committee has had B-tree proposals since at least 2019 and none have been adopted.

On our workload, swapping std::map for absl::btree_map gave a modest 9% P99 improvement — the tree isn't the dominant bottleneck. But the p50 dropped from 1,240 to 899 cycles, a 28% median improvement. Every std::map in a hot path is leaving performance on the table, even when it's not the primary bottleneck.

Failure #3: std::list — The Container That Should Not Exist

This one is inexcusable. std::list is a doubly-linked list with per-node heap allocation. In 2026. On hardware where a cache miss costs 50-200 cycles and a malloc/free round-trip costs 100-500 cycles.

Our order book has ~500K active orders distributed across ~200 symbols with tick-snapped prices. That means hundreds of orders per price level. When a cancel arrives, we linear-scan the FIFO queue at that level looking for the order ID. With std::list, that scan follows pointers to randomly scattered heap nodes. Each pointer chase is a potential cache miss. Each node was individually new'd and will be individually delete'd.

Rust doesn't even have a linked list in its standard collections. It has LinkedList in std::collections but the documentation literally says "it is almost always better to use Vec or VecDeque." The Rust standard library actively discourages linked lists. The C++ standard library makes std::list a first-class container with full iterator support, allocator integration, and merge/splice operations that nobody in HFT would ever use.

The Fix: Replacing The Standard Library

We systematically replaced each C++ container with its actual algorithmic equivalent:

# Change P99 Improvement
1 Baseline: unordered_map + map + list 302,653 —
2 flat_hash_map + map + deque 9,951 30x
3 flat_hash_map + btree_map + deque 9,114 1.09x
4 flat_hash_map + btree_map + vector 4,268 2.1x
— Rust stdlib (HashMap + BTreeMap + VecDeque) 5,177 —

71x improvement from using better containers alone. No algorithmic changes. Same code structure. Same O(n) queue scan. Just containers that respect how modern CPUs actually work.

C++ with flat_hash_map + btree_map + vector scores 4,268 — actually slightly faster than Rust's 5,177. The languages are equivalent when you use equivalent data structures. The problem is that C++ makes you go find them yourself.

The std::deque Trap

One dead end deserves special attention because it reveals how deep the naming problem goes.

When we replaced std::list with std::deque, we thought we were done with the queue problem. After all, Rust's VecDeque is literally "Vec-Deque" — a deque backed by a vector. std::deque is C++'s deque. Same concept, right?

No. std::deque is implemented as an array of pointers to fixed-size blocks (~512 bytes each). It's a chunked data structure with pointer indirection between blocks. For our cancel scan — iterate through elements, find a match, erase — the CPU has to follow a pointer every ~32 elements to reach the next block. Erase shifts elements across block boundaries.

Rust's VecDeque is a contiguous ring buffer. One allocation. Sequential memory access. Erase is a memmove. The CPU prefetcher handles it perfectly.

Queue Implementation P99 p50 avg
std::list (linked list) ~302K 1,581 22,532
std::deque (chunked blocks) 9,114 899 1,793
std::vector (contiguous) 4,268 554 947
Rust VecDeque (contiguous ring) 5,177 713 1,026

The naming actively misleads. A C++ developer reading "VecDeque" in Rust and looking for the C++ equivalent will pick std::deque. They'll get 2x worse P99 for their trouble. The actual equivalent is std::vector with a convention to only push_back and erase from the middle — an informal contract that no type system enforces.

Other Things We Tried (And Why They Failed)

Identity Hash: 3.3x Worse

Sequential order IDs. Identity hash seems optimal — just return the key, skip the mixing. P99 exploded from 13,288 to 43,627. Swiss Table uses groups of 16 control bytes probed with SIMD. Sequential keys with identity hash land in the same group, creating probe chain pileups. The hash function's bit-mixing isn't overhead — it's load balancing.

struct IdentityHash {
    size_t operator()(uint64_t k) const noexcept {
        return k;  // Sequential IDs → clustered probes
    }
};
// P99: 43,627 (was 13,288 with absl default)

Allocator Hypothesis: Irrelevant

We suspected Rust might use jemalloc. Rust switched to the system allocator (glibc malloc) in version 1.32 back in 2019. Both languages use the same allocator. The 58x gap has nothing to do with allocation strategy and everything to do with how many allocations the containers make in the first place.

GCC vs Clang: 20% At P99

Running the same C++ solution through both compilers on the same machine:

Compiler P99 p50 avg
GCC 13.3 13,288 753 1,718
Clang 18 (LLVM) 10,677 763 1,553

Clang is 20% faster at P99, identical at p50. The difference is in tail latency — different inlining heuristics and loop optimizations. Since Rust uses LLVM (same backend as Clang), the C++ benchmark on GCC has a built-in 20% handicap on tail latency. Not the dominant factor, but it compounds.

The Committee Knows And Doesn't Care

This isn't new information. The C++ committee has known about these problems for at least a decade — and has an enormous apparatus dedicated to the standard library that still hasn't fixed them.

WG21 — the ISO C++ committee — has 23 active subgroups. Eight of them are directly focused on library work: LWG (Library Wording, 5 chairs), LEWG (Library Evolution, 3 chairs), SG18 (LEWG Incubator), SG9 (Ranges), SG4 (Networking), SG6 (Numerics), SG16 (Unicode), and SG19 (Machine Learning). That's 35% of the committee's subgroups devoted to the standard library. Plus five more dormant groups (Modules, File System, Transactional Memory, Databases, Concepts) that were also largely library work.

Around 200 people attend each meeting — three times a year, in cities worldwide (Croydon, Brno, Búzios in 2026). At $2-3K travel per person per meeting plus $1,300/year membership fees. Thirty-five years of committee work, representing over 20 national bodies, and the default hash map still uses chained buckets with per-node heap allocation.

absl::flat_hash_map was open-sourced in 2017. Proposals for better default containers have circulated since C++17 discussions. std::flat_map — a sorted flat container, not even a hash map — took six years to land in C++23, and most standard library implementations still don't ship it. There is no std::flat_hash_map. There is no std::btree_map. There is no contiguous-memory deque.

The ABI stability promise makes replacing std::unordered_map's implementation impossible without breaking binary compatibility. So it stays chained, stays slow, stays the default. The committee chose ABI stability over performance. Every C++ developer paying the std::unordered_map tax in production is subsidizing that decision.

Rust doesn't have this problem. HashMap's implementation was swapped from Robin Hood hashing to Swiss Table in Rust 1.36 (2019) with zero ABI concerns — Rust doesn't promise binary ABI stability across versions, so the standard library can ship better implementations when they exist. And it does.

What This Means For Your Code

If you're writing latency-sensitive C++ in 2026 and you're still using std::unordered_map, std::map, or std::list — stop. You are leaving 10-70x performance on the table. Not through algorithmic improvements or clever optimizations, but through containers that respect cache lines.

The minimum viable replacements:

Don't Use Use Instead Why
std::unordered_map absl::flat_hash_map Open addressing, inline storage
std::map absl::btree_map B-tree, cache-friendly nodes
std::list std::vector Contiguous memory, no per-node alloc
std::deque std::vector Contiguous, not chunked blocks

Or switch to Rust, where the standard library ships the right defaults and you don't need to know any of this. A junior Rust developer using HashMap, BTreeMap, and VecDeque — the first containers they'll find in any tutorial — gets 5,177 cycles P99 on a workload that punishes bad containers mercilessly. A junior C++ developer using the standard library gets 302,653.

That's not a skill gap. That's a standard library gap. And after 28 years of C++ standardization, the committee still hasn't closed it.

The Challenge

Both C++ and Rust challenge-02 now share identical infrastructure — same workload generator, same venue, same scoring. Badge thresholds are the same: gold 2,200, silver 3,500, bronze 4,500 P99 cycles/op. Neither naive skeleton earns a badge. Gold requires custom allocators, flat arrays, bitmap-indexed price levels — real data structure engineering that goes beyond any standard library in any language.

Try it yourself.

Review quiz

Pass it to mark this article as read and count it toward your reading achievements.

Five questions about this article. Get four right and it counts as read. Review quizzes come with a membership.

Log in See membership

Back to Courses
926 reads 1

Comments (2)

Peter S. Aug 02, 2026

frankly speaking, I never expected the standard library to provide the fastest implementation, anyway.
it's meant to be general-purpose & easy to use.

the standard library doesn't relieve you from doing proper research. first know the internals of your data structures, then choose wisely.

0
Baseline (reference solution) Aug 03, 2026

That is the point - Rust's standard library is general purpose, easy to use AND 58x faster.

0
Log in as a member to comment, or subscribe to join the discussion.