Benchmarks

Measured on 12th Gen Intel Core i7-12700H, Linux, GCC 15.2, 2026-11-15. Release build (-O2), one pinned core (threads: eight cores). Reproduce with:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build
./build/bench_rss 2000000
./build/bench_runtime 4194304 10000 list     # or map, hash, arithmetic, ...

The plf::list results need a plf_list checkout (7.6.50 or later):

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
  -DCOMPRESSED_PTR_PLF_LIST_DIR=/path/to/plf_list && cmake --build build
./build/bench_runtime 4194304 10000 plf
scripts/make_bench_page.py runtime.md rss.txt > docs/benchmarks.md

For a quick check on your own machine, run ./build/example_expect_gains: it prints memory per element and time per operation for each std container against its cptr counterpart.

Summary

Compressed against raw pointers

The same container or loop with 4-byte compressed pointers against raw 8-byte pointers, at five points of the latency distribution. Bars left of zero are faster than raw pointers. Hover a bar for its value.

p50p90p95p99p99.5

−60%−40%−20%0+20%+40%+60%← faster than raw pointersslower →list push_backlist push_back, p50: -26% against raw pointerslist push_back, p90: -23% against raw pointerslist push_back, p95: -24% against raw pointerslist push_back, p99: -5% against raw pointerslist push_back, p99.5: -7% against raw pointerslist walklist walk, p50: -12% against raw pointerslist walk, p90: -14% against raw pointerslist walk, p95: -13% against raw pointerslist walk, p99: -8% against raw pointerslist walk, p99.5: +2% against raw pointersordered_map insertordered_map insert, p50: -5% against raw pointersordered_map insert, p90: -3% against raw pointersordered_map insert, p95: -3% against raw pointersordered_map insert, p99: -1% against raw pointersordered_map insert, p99.5: -1% against raw pointersordered_map findordered_map find, p50: -4% against raw pointersordered_map find, p90: -4% against raw pointersordered_map find, p95: -4% against raw pointersordered_map find, p99: -3% against raw pointersordered_map find, p99.5: -4% against raw pointersunordered_map insertunordered_map insert, p50: -1% against raw pointersunordered_map insert, p90: +1% against raw pointersunordered_map insert, p95: +1% against raw pointersunordered_map insert, p99: +5% against raw pointersunordered_map insert, p99.5: +6% against raw pointersunordered_map findunordered_map find, p50: +15% against raw pointersunordered_map find, p90: +16% against raw pointersunordered_map find, p95: +18% against raw pointersunordered_map find, p99: +11% against raw pointersunordered_map find, p99.5: +9% against raw pointerspointer chase, L1pointer chase, L1, p50: +55% against raw pointerspointer chase, L1, p90: +39% against raw pointerspointer chase, L1, p95: +42% against raw pointerspointer chase, L1, p99: +31% against raw pointerspointer chase, L1, p99.5: +20% against raw pointerspointer chase, L1, nonnull_ptrpointer chase, L1, nonnull_ptr, p50: +16% against raw pointerspointer chase, L1, nonnull_ptr, p90: +5% against raw pointerspointer chase, L1, nonnull_ptr, p95: +6% against raw pointerspointer chase, L1, nonnull_ptr, p99: +2% against raw pointerspointer chase, L1, nonnull_ptr, p99.5: -5% against raw pointerspointer chase, L2pointer chase, L2, p50: +7% against raw pointerspointer chase, L2, p90: +6% against raw pointerspointer chase, L2, p95: +5% against raw pointerspointer chase, L2, p99: -15% against raw pointerspointer chase, L2, p99.5: -23% against raw pointerspointer chase, L3pointer chase, L3, p50: -42% against raw pointerspointer chase, L3, p90: -30% against raw pointerspointer chase, L3, p95: -28% against raw pointerspointer chase, L3, p99: -20% against raw pointerspointer chase, L3, p99.5: -17% against raw pointerspointer chase, DRAMpointer chase, DRAM, p50: -3% against raw pointerspointer chase, DRAM, p90: -3% against raw pointerspointer chase, DRAM, p95: -3% against raw pointerspointer chase, DRAM, p99: -0% against raw pointerspointer chase, DRAM, p99.5: -1% against raw pointers

Benchmark raw p50 ns Δp50 Δp90 Δp95 Δp99 Δp99.5
list push_back 10.56 −26% −23% −24% −5% −7%
list walk 1.88 −12% −14% −13% −8% +2%
ordered_map insert 836.08 −5% −3% −3% −1% −1%
ordered_map find 968.76 −4% −4% −4% −3% −4%
unordered_map insert 73.60 −1% +1% +1% +5% +6%
unordered_map find 44.89 +15% +16% +18% +11% +9%
pointer chase, L1 1.24 +55% +39% +42% +31% +20%
pointer chase, L1, nonnull_ptr 1.24 +16% +5% +6% +2% −5%
pointer chase, L2 3.32 +7% +6% +5% −15% −23%
pointer chase, L3 39.85 −42% −30% −28% −20% −17%
pointer chase, DRAM 90.60 −3% −3% −3% −0% −1%

Tails matter as much as medians: the p99 and p99.5 bars show the slowest 1% and 0.5% of epochs. Compression helps most there for structures that outgrow the caches, because half as much memory is touched.

Memory

Resident set growth for 2,000,000 elements, per element. "Cage, raw links" is the same container and allocator with 8-byte links, which separates the effect of compression from the effect of the header-less allocator.

Structure std cage, raw links cage, compressed compressed vs std
list of uint32_t 32.0 B 24.1 B 16.1 B −50%
map uint32_t → uint32_t 48.0 B 40.1 B 24.1 B −50%
hash map uint32_t → uint32_t 43.8 B 32.6 B 20.4 B −53%
graph, 16 edges per vertex 168.0 B — 88.1 B −48%
plf::list of uint32_t (std column: plain plf::list) 24.1 B — 12.2 B −49%

How the time is measured

bench_runtime uses nanobench. Each benchmark runs thousands of short epochs of a few hundred operations on a structure that stays large for the whole run, and reports the 50th, 90th, 95th, 99th and 99.5th percentile of the time per element. Each variant is compared with a reference at the same percentile: Δp99 = +10% means its p99 is 10% slower than the reference's p99. The reference is the same container with raw 8-byte links, or a raw T*. Variants run interleaved, in bursts of 8 epochs, so frequency changes and other drift affect all of them alike. Up to p99 two runs agree within a few percent; p99.5 is the 50th-slowest of 10,000 samples and moves more.

Linked list

list of uint32_t, 4194304 elements, ns per element (chunks of 512, walk 4096)

p50 ns p99.5 ns Δp50 Δp90 Δp95 Δp99 Δp99.5
grow: cptr::list raw links 10.6 50.9 ref ref ref ref ref
grow: cptr::list compressed 7.79 47.2 −26% −23% −24% −5% −7%
grow: std::list 19 66.3 +80% +71% +77% +89% +30%
walk: cptr::list raw links 1.88 6.45 ref ref ref ref ref
walk: cptr::list compressed 1.65 6.56 −12% −14% −13% −8% +2%
walk: std::list 2.35 7.77 +25% +26% +24% +15% +21%
shrink: cptr::list raw links 8.95 43.4 ref ref ref ref ref
shrink: cptr::list compressed 7.07 47.6 −21% −29% −19% −2% +10%
shrink: std::list 5.35 29 −40% −62% −63% −56% −33%

The compressed list grows faster than the raw one because it commits and touches half as much memory, and walks faster because twice as many nodes fit in a cache line. std::list pops faster: glibc's free is cheaper than the cage allocator's deallocate.

plf::list with cptr::fancy_allocator

plf::list takes its node pointer type from its allocator, so cptr::fancy_allocator gives it 4-byte links with no change to its code. The reference here is plain plf::list with std::allocator; the compressed list object lives in the cage, as it must (see the guide).

plf::list of uint32_t, 4194304 elements, ns per element (chunks of 512, walk 4096)

p50 ns p99.5 ns Δp50 Δp90 Δp95 Δp99 Δp99.5
grow: plf::list 8 39.5 ref ref ref ref ref
grow: plf::list with cptr::fancy_allocator 5.09 25.6 −36% −44% −32% −37% −35%
grow: std::list 19.3 67.3 +141% +109% +109% +186% +71%
walk: plf::list 1.71 2.55 ref ref ref ref ref
walk: plf::list with cptr::fancy_allocator 1.49 2.28 −13% −15% −18% −15% −10%
walk: std::list 2.06 3.05 +20% +22% +25% +23% +20%
shrink: plf::list 2.6 24.1 ref ref ref ref ref
shrink: plf::list with cptr::fancy_allocator 2.17 35.7 −17% −31% −32% −3% +48%
shrink: std::list 5.41 33.2 +108% +43% +41% +43% +37%

plf::list sort() of 262144 random uint32_t, ns per element

p50 ns p99.5 ns Δp50 Δp90 Δp95 Δp99 Δp99.5
plf::list 83.9 107 ref ref ref ref ref
plf::list with cptr::fancy_allocator 80.1 99.2 −4% −10% −9% −7% −7%
std::list 188 275 +125% +138% +164% +157% +157%

Each sort epoch first overwrites the list's values with fresh random ones, in list order, and the time includes that walk. plf::list sorts by copying node pointers into an array, sorting the array and relinking, so the link size matters less there than in a walk. With only about a hundred sort epochs, its p99 and p99.5 are a single slow epoch and move a lot between runs. The same goes for the slowest 0.5% of pops, which ranged from 50% faster to 48% slower over two runs; up to p95 they agree within a few percent. The memory table above has its bytes per element.

Ordered map

map uint32_t -> uint32_t, 4194304 random keys, ns per element

p50 ns p99.5 ns Δp50 Δp90 Δp95 Δp99 Δp99.5
grow: cptr::ordered_map raw links 836 1578 ref ref ref ref ref
grow: cptr::ordered_map compressed 794 1564 −5% −3% −3% −1% −1%
grow: std::map 909 1753 +9% +9% +10% +10% +11%
find: cptr::ordered_map raw links 969 1713 ref ref ref ref ref
find: cptr::ordered_map compressed 927 1644 −4% −4% −4% −3% −4%
find: std::map 1021 1903 +5% +7% +7% +10% +11%
walk: cptr::ordered_map raw links 107 167 ref ref ref ref ref
walk: cptr::ordered_map compressed 105 158 −2% −3% −4% −5% −5%
walk: std::map 109 170 +2% +2% +2% +1% +2%
shrink: cptr::ordered_map raw links 1027 1933 ref ref ref ref ref
shrink: cptr::ordered_map compressed 1007 1839 −2% −5% −5% −6% −5%
shrink: std::map 972 1748 −5% −7% −7% −8% −10%

cptr::ordered_map is a red-black tree like std::map, with 24-byte instead of 48-byte nodes for 4-byte keys and values.

Hash map

hash map uint32_t -> uint32_t, 4194304 random keys, ns per element

p50 ns p99.5 ns Δp50 Δp90 Δp95 Δp99 Δp99.5
grow: cptr::unordered_map raw links 73.6 153 ref ref ref ref ref
grow: cptr::unordered_map compressed 72.9 162 −1% +1% +1% +5% +6%
grow: std::unordered_map 113 210 +54% +41% +41% +34% +37%
find: cptr::unordered_map raw links 44.9 98.8 ref ref ref ref ref
find: cptr::unordered_map compressed 51.5 108 +15% +16% +18% +11% +9%
find: std::unordered_map 29.3 82.4 −35% −32% −32% −18% −17%
walk: cptr::unordered_map raw links 101 157 ref ref ref ref ref
walk: cptr::unordered_map compressed 98.2 150 −3% −4% −4% −4% −5%
walk: std::unordered_map 21.4 126 −79% −31% −29% −21% −20%
shrink: cptr::unordered_map raw links 72.5 136 ref ref ref ref ref
shrink: cptr::unordered_map compressed 81 150 +12% +10% +9% +12% +10%
shrink: std::unordered_map 108 183 +50% +33% +33% +36% +35%

These keys are 0 to n − 1, inserted in random order. std::hash<uint32_t> is the identity, so std::unordered_map gives every such key a bucket of its own, which favours it at find. With keys spread over the 32-bit range (as in example_expect_gains), or with a mixing hash, cptr::unordered_map finds as fast or faster. std::unordered_map keeps its nodes on one list in allocation order, so it walks memory nearly in order; cptr::unordered_map walks bucket by bucket.

Allocator

Allocator: free a random block of 65,536 and allocate 16 to 256 bytes, ns per free and allocate

p50 ns p99.5 ns Δp50 Δp90 Δp95 Δp99 Δp99.5
malloc / free 17.6 75.7 ref ref ref ref ref
cage allocate / deallocate 10.1 53.1 −43% −66% −67% −48% −30%

Allocator churn on several threads, ns per free and allocate on each thread

p50 ns p99.5 ns Δp50 Δp90 Δp95 Δp99 Δp99.5
1 threads, malloc / free 10.8 33.6 ref ref ref ref ref
1 threads, cage 7.93 18.7 −27% −34% −31% −51% −44%
2 threads, malloc / free 13.6 43.1 ref ref ref ref ref
2 threads, cage 8.54 17.9 −37% −38% −41% −60% −58%
4 threads, malloc / free 13 34 ref ref ref ref ref
4 threads, cage 9.01 26 −31% −24% −26% −24% −23%
8 threads, malloc / free 25.3 68.8 ref ref ref ref ref
8 threads, cage 15.8 37.2 −38% −35% −41% −56% −46%

Each thread keeps a cache of up to 32 freed blocks per size class and takes the cage's lock only to refill or flush half of it.

Pointer chasing

A random cycle through n nodes. This is where the decompression add sits on the critical path of every load.

Pointer chasing, random cycle, 4 B payload (node 8 B compressed, 16 B raw), ns per step

p50 ns p99.5 ns Δp50 Δp90 Δp95 Δp99 Δp99.5
1024 nodes, raw T* 1.24 3.04 ref ref ref ref ref
1024 nodes, ptr 1.92 3.65 +55% +39% +42% +31% +20%
1024 nodes, nonnull_ptr 1.44 2.88 +16% +5% +6% +2% −5%
16384 nodes, raw T* 3.32 9.65 ref ref ref ref ref
16384 nodes, ptr 3.57 7.44 +7% +6% +5% −15% −23%
16384 nodes, nonnull_ptr 3.15 7.98 −5% −6% −6% −17% −17%
262144 nodes, raw T* 39.9 107 ref ref ref ref ref
262144 nodes, ptr 23.1 88.8 −42% −30% −28% −20% −17%
262144 nodes, nonnull_ptr 22.6 84.9 −43% −31% −28% −22% −20%
4194304 nodes, raw T* 90.6 133 ref ref ref ref ref
4194304 nodes, ptr 87.6 131 −3% −3% −3% −0% −1%
4194304 nodes, nonnull_ptr 87 131 −4% −4% −4% −2% −1%

Pointer chasing, random cycle, 56 B payload (node 60 B compressed, 64 B raw), ns per step

p50 ns p99.5 ns Δp50 Δp90 Δp95 Δp99 Δp99.5
1024 nodes, raw T* 3.31 4.86 ref ref ref ref ref
1024 nodes, ptr 3.84 5.37 +16% +16% +15% +12% +10%
1024 nodes, nonnull_ptr 3.39 4.95 +3% +2% +2% −0% +2%
16384 nodes, raw T* 14.2 57.6 ref ref ref ref ref
16384 nodes, ptr 14.4 51.7 +2% +2% −1% −8% −10%
16384 nodes, nonnull_ptr 13.9 52 −2% −4% −6% −9% −10%
262144 nodes, raw T* 91.4 143 ref ref ref ref ref
262144 nodes, ptr 91.3 143 −0% −0% −0% +0% −0%
262144 nodes, nonnull_ptr 90.9 142 −0% −0% −0% −0% −0%
4194304 nodes, raw T* 104 183 ref ref ref ref ref
4194304 nodes, ptr 104 182 −0% −1% −2% −3% −1%
4194304 nodes, nonnull_ptr 104 180 −1% −0% −2% −2% −2%

In L1 and L2 the add and the null check show; nonnull_ptr has no null check and costs much less. From L3 on, the smaller nodes win.

Pointer arithmetic and conversions

Pointer arithmetic: ++p over an array of uint32_t, ns per element

p50 ns p99.5 ns Δp50 Δp90 Δp95 Δp99 Δp99.5
65536 elements, raw T* 0.09 0.24 ref ref ref ref ref
65536 elements, ptr 0.32 0.56 +247% +206% +188% +131% +128%
4194304 elements, raw T* 0.2 3.14 ref ref ref ref ref
4194304 elements, ptr 0.32 0.46 +58% +30% +24% −57% −85%

The raw loop is vectorised. A 32-bit offset that may wrap is not an induction variable the compiler can turn into a pointer, so the ptr loop stays scalar. In a hot loop over an array, convert to T* once with get().

Conversion of 4,096 ptr<int>, ns per conversion

p50 ns p99.5 ns Δp50 Δp90 Δp95 Δp99 Δp99.5
copy to ptr<int> 0.09 0.22 ref ref ref ref ref
to ptr<const int> 0.09 0.21 +4% +2% −1% −2% −4%
to ptr<void> 0.09 0.21 +4% +3% +2% −1% −5%