Skip to content
gofractallyPublic

About

artpp::map — header-only adaptive radix tree map for C++23. Headerless dispatch, O(key-length) ops, allocator-aware, faster point lookups than libart and absl::btree.

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

libart++

libart++ — artpp::map, a header-only adaptive radix tree map for C++20

Website & benchmark charts

Release 0.1.0, measured 2026-11-28 on an Apple M5 Max and on an x86-64 Linux server (AMD EPYC-Turin):

  • A C++ container where libart is a C library. libart maps byte strings to void* and iterates through callbacks; artpp::map has the std::map interface, typed keys and values, iterators in both directions, lower_bound / upper_bound, allocator support and stated exception-safety guarantees (what the C++ API adds). Point lookups against libart: on the Apple M5 Max 1.14–1.97× faster on all four workloads with both allocators; on the x86-64 server 1.06–1.11× on dictionary words, 0.96–1.05× on clustered strings, 1.44–3.49× on sequential integers and 0.68–0.78× on uniform random integers, which is slower.
  • Faster than unodb, the other general-purpose C++ ART, on both machines: on random 32-byte keys, 10M of them, lookups are 4.76–4.77× (M5) and 4.24–4.36× (x86) faster, inserts 2.94–4.01× (M5) and 2.16–3.49× (x86), ordered scans 11.71–12.38× (M5) and 5.18–5.62× (x86) and lower_bound 4.58–4.90× (M5) and 1.94–2.04× (x86); the ranges cover both allocators.
  • More general than the other C++ ARTs. art_map cannot hold a key longer than 16 bytes, so it has no string keys. unodb requires that no key be a prefix of another (its text keys go through an encoder that truncates and pads them) and stores values that are byte spans or trivially copyable. artpp::map takes byte strings of any content up to 65535 bytes, integers and any type with a key_codec, and stores any move-constructible C++ value (details). There is no current measurement against art_map, so no speed claim is made against it.
  • It can live in a file. With the bundled line_pool the map is stored in a file and reopened without a rebuild. Measured under File-backed: against boost::multi_index_container with one ordered index in a Boost.Interprocess mapped file, on the four workloads of the main suite, lookups are 2.63–16.99× faster on the M5 and 2.63–31.63× on the x86-64 server, inserts 2.16–22.03× and 2.41–14.93×, lower_bound 1.03–4.92× and 1.30–5.14×. Boost reopens a store sooner (49–66 µs to the first lookup against artpp's 130–146 µs on the M5; 30–61 µs against 39–78 µs on the x86-64 server), closes it sooner, and needs fewer bytes per key on dictionary words and uniform integers (84.79–84.90 against 80.00–80.01 B/key; 66.88–66.97 against 56.00–64.00 B/key), where artpp needs fewer on clustered strings and sequential integers (66.37–66.39 against 80.00 B/key; 26.17 against 56.00–64.00 B/key). Boost.MultiIndex holds several indexes over one element, which artpp does not.

Against the comparison-based maps, point lookups are 1.72–3.13× absl::btree_map and 2.15–6.83× std::map on the M5, and 0.87–3.47× and 1.79–8.05× on the x86-64 server (below 1 is slower: uniform random integers with std::allocator). Where artpp is slower: on the x86-64 server, lookups of uniform random integers (0.68–0.78× libart) and misses on clustered, uniform and sequential keys (0.49–0.87× libart); on both machines, inserts of dictionary words (0.51–0.87× libart), lower_bound and erase on uniform random integers (0.49–0.89× and 0.37–0.92× absl::btree_map), and ordered scans in the default mode, which are slower than absl::btree_map's in 16 of 16 cells (0.05–0.69×). The tables under Performance show every cell, including these.

The design rule of the lookup path: at most one cold cacheline per level of descent — headerless tagged-pointer dispatch; prefixes fused into the node's own header line; small values inline in the handle; a small leaf living inside the routing node's cacheline (the inl byte); and larger leaves in a dedicated 16-byte-aligned terminal region (a terminal is pure payload — it doesn't pay for a 128-byte line).

artpp::map<Key, T> is an ordered associative container backed by an adaptive radix tree (ART) with headerless dispatch: the node kind rides in the tagged pointer, so descent never loads a header byte before deciding how to route. Keys are stored as their encoded bytes along the tree paths; values live inline in the pointer when small and trivially copyable, otherwise in compact leaf allocations.

It offers the familiar std::map-style surface — ordered iteration, bounds, find/erase/at/operator[], allocator awareness — with radix-tree complexity: every operation is O(key length), independent of element count, with no comparisons and no rebalancing.

#include "artpp/map.hpp"
#include <iostream>

artpp::map<std::string_view, uint64_t> t;
t.insert("alpha", 1);             // insert or assign; true iff newly inserted
t.emplace("beta", 2);             // insert only if absent (never overwrites)
t.try_emplace("beta", 99);        // present → untouched, nothing constructed

if (auto it = t.find("alpha"); it != t.end())
    use(it->first, it->second);

for (const auto& [key, value] : t)         // ascending key order
    std::cout << key << " = " << value << '\n';

t.erase("beta");

String-keyed maps take std::string_view arguments regardless of the owning key type — artpp::map<std::string, T> and artpp::map<std::string_view, T> share one parameter signature, so literals, char*, views, and strings all pass with no temporary std::string ever constructed:

artpp::map<std::string, int> owning;   // keys stored/decoded as std::string
owning.insert("alice", 1);             // literal: no temporary
std::string_view sv = user_input();
owning.contains(sv);                   // view: no temporary

Integral keys work out of the box and iterate in numeric order:

artpp::map<int64_t, std::string> m;     // big-endian, sign-flipped encoding:
m.insert(-5, "neg");                      // byte order == numeric order
m.insert(7, "pos");                       // iteration yields -5 before 7

Contents

Building and integrating

Header-only — copy include/artpp or use CMake:

cmake -B build && cmake --build build && ctest --test-dir build

As a dependency (FetchContent or add_subdirectory), link artpp::artpp:

include(FetchContent)
FetchContent_Declare(artpp GIT_REPOSITORY https://github.com/gofractally/libartpp.git
                     GIT_TAG main)
FetchContent_MakeAvailable(artpp)
target_link_libraries(your_target PRIVATE artpp::artpp)

Or install it and use find_package:

cmake -B build -DARTPP_TESTS=OFF && cmake --install build --prefix /your/prefix
find_package(artpp 0.1 REQUIRED)
target_link_libraries(your_target PRIVATE artpp::artpp)

<artpp/version.hpp> defines ARTPP_VERSION (and _MAJOR, _MINOR, _PATCH, _STRING).

CMake option Default Effect
ARTPP_TESTS ON when top-level The functional suite, run by ctest
ARTPP_BENCHMARKS OFF The benchmark/compare suite: vendors upstream libart, uses absl::btree_map (installed or fetched)
ARTPP_BENCH_FILEBACKED OFF artpp_bench_filebacked alone (also part of ARTPP_BENCHMARKS); needs the Boost headers, skipped without them
ARTPP_WITH_PSIO OFF The psio key-format codec adapter and its test (needs C++23 and the Boost headers, as psio does)
ARTPP_FUZZER OFF The coverage-guided libFuzzer target artpp_fuzzer (Fuzzing)
ARTPP_PSIO_SOURCE_DIR — Path to an existing psio checkout (skips the fetch)

Requirements

  • C++20 (<bit>, requires-clauses, if constexpr; std::byteswap when available, else a __builtin_bswap shim).
  • A 64-bit, little-endian target (both statically asserted) with 48-bit virtual addresses for the default 6-byte handle; an allocator can select 8-byte handles to lift the VA assumption (Allocators). The assumption is checked at run time, once per allocation: a block above 2^48 (top-byte pointer tagging such as HWASan or MTE, 5-level paging, 52-bit ARM addresses) makes the allocating operation throw artpp::bad_allocation_address instead of being truncated.
  • No particular instruction set: the router probes use NEON (ARM64) or SSE2 (x86-64) when the compiler targets them, selected automatically, with a scalar fallback (the two-byte wide-stem probe is NEON or scalar).
  • No dependencies beyond the standard library. Header-only: #include <artpp/map.hpp> (and artpp/pool.hpp for the optional line pool). The optional psio adapter is the exception: it needs psio, and with it C++23 and the Boost headers.
  • A POSIX system for artpp::line_pool (mmap); the map itself with std::allocator or any other allocator does not need it.
  • Tested in CI with GCC and Clang on x86-64 Linux and Apple Clang on ARM64 macOS, each also under AddressSanitizer and UndefinedBehaviorSanitizer, and with GCC on ARM64 Linux (no sanitizers). The psio adapter, the benchmarks and the libFuzzer target are not built in CI. MSVC is not supported.

Template parameters

template <class Key, class T,
          artpp::mode Mode         = artpp::mode::none,
          class       Allocator    = std::allocator<T>,
          std::size_t ExpectedSize = 0>
class map;
Parameter Meaning
Key Any type with a key_codec specialization. Built in: std::string, std::string_view, std::vector<uint8_t>, all integral types (including bool, which orders false before true, and the character types).
T The mapped type. Move-constructible required; copy/equality/default-constructibility are required only by the operations that use them (default construction: operator[] and find_opt). alignof(T) up to 128 (Limits and guarantees).
Mode Structural policy flags, combinable with | (below).
Allocator A standard allocator. Every node and every value is allocated and constructed through it (Allocators).
ExpectedSize Optional capacity hint. When small (0 < ExpectedSize ≤ 3,000,000) it auto-selects the compact cnode density ladder — a perf-per-byte win for small maps (see compact_map). 0 (unknown) leaves the fast flat default.

Modes

Flag Effect
mode::none Pure radix: leaves, prefix nodes, and routers that widen setlist → node_full. The default.
mode::buckets Terminals are buckets — packed (suffix, value) pages whose index is kept in total suffix order by insertion, collapsing sparse or deep key tails into one node. Routers appear only when a bucket overflows and bursts. Measured against the default mode under Bucket mode: on dictionary words it looks up and scans faster, on clustered strings it scans faster and looks up more slowly, and on sequential integers it is slower at both. Buckets cost nothing when off: the engine dead-strips from other modes.
mode::adaptive Pure radix that watches its own descent: when leaf splits keep landing under deep, narrow paths, those split points collapse to buckets. A middle ground that keeps uniform data bucket-free.
mode::dense_tiers Forces the segmented-bitset cnode density ladder on (setlist → c2 → c4 → node_full): sparse fan-out routers stay compact cnodes instead of a sparse node_full (14 lines with the default handle, 10 on the line_pool). On the line_pool this is a perf-per-byte win for small maps — below ~3M keys ~40% less RAM and ~2× faster build, as measured by artpp_widen_probe — but the gain fades as the map grows (fan-out nodes densify toward node_full and leaves come to dominate the footprint), and past ~3M it only adds build churn + pool fragmentation. Usually reached via the ExpectedSize hint / compact_map rather than set by hand.
mode::flat_full Forces the ladder off (setlist → node_full direct) even when a capacity hint would enable it — the plain-radix behavior, for find-only or large maps. Same as the default mode::none.
mode::ladder_c8 Adds the c8 rung to the ladder (… → c4 → c8 → node_full). Off by default — on bimodal data c8 is ~never the final tier — and kept for testing adversarial mid-density-clustered fan-outs. Only meaningful combined with the ladder.
mode::wide_stems Sparse routers consume two key bytes per hop (setlist_u16), halving router-hop depth on deep sparse trees; nodes re-stride back to one-byte routers when they densify.

All modes share the same external semantics; the flags select internal representations only. The default, buckets, adaptive, dense_tiers (with and without ladder_c8) and wide_stems are each exercised against std::map by the test suite; flat_full and the capacity hint only choose between two of those representations and have shape checks, not differential runs of their own.

compact_map (capacity hint)

template <class Key, class T, std::size_t ExpectedN, class Allocator = std::allocator<T>>
using compact_map = artpp::map<Key, T, artpp::mode::none, Allocator, ExpectedN>;

artpp::compact_map<std::string_view, uint64_t, 500'000> small;  // → cnode density ladder

Declaring roughly how many keys you expect lets the map pick the better internal representation automatically. The default map widens sparse fan-out routers straight to a node_full (14 lines with the default handle, 10 on the line_pool); at small scale those nodes are genuinely sparse (~30 of 256 branches), so on the line_pool a compact_map stores them as 2–4-line cnodes instead (3–5 lines with the default handle) — ~40% less RAM and ~2× faster to build below ~3M keys, with point/ordered lookups within noise (measured with artpp_widen_probe, bench/widen_probe.cpp). Above the measured crossover the hint transparently falls back to the flat default (the ladder would only add build churn and pool fragmentation once fan-out nodes saturate toward node_full and leaf storage dominates the footprint). The crossover is a measured constant (ladder_capacity_max); for explicit control use mode::dense_tiers (force on) or mode::flat_full (force off).

Key types and key_codec

The radix orders keys by their encoded bytes (lexicographic, unsigned). artpp::key_codec<Key> is the customization point that maps a typed key to those bytes and back:

template <>
struct artpp::key_codec<MyKey>
{
   // EITHER zero-copy (contiguous keys):
   static constexpr bool   zero_copy = true;
   static std::string_view view(const MyKey& k) noexcept;

   // OR serializing (the default protocol):
   static std::string_view encode(const MyKey& k, std::string& scratch);

   static MyKey decode(std::string_view bytes);   // stored bytes -> key
};
  • Zero-copy codecs never touch a scratch buffer on the lookup path.
  • A serializing codec may define its own scratch type; the integral codec uses a fixed char[sizeof(K)] so no std::string machinery runs per operation.
  • Integral keys encode fixed-width big-endian with the sign bit flipped for signed types, so byte order equals numeric order — iteration, lower_bound, and upper_bound follow numeric semantics exactly.
  • decode is why iteration returns a Key, not a const Key&: a key has no stored object to reference; it is rebuilt from the path bytes on demand. (The built-in std::string_view codec decodes to a view of those bytes, which is why such a key is only valid while its iterator stays put — see Iterators.)

Arbitrary key types via psio

With ARTPP_WITH_PSIO, <artpp/psio_codec.hpp> adapts psio's key format — memcmp-sortable encodings for bools, integrals, doubles (IEEE sign-transform), strings, optionals, vectors, variants, and any PSIO_REFLECT'ed struct — as an artpp key codec. Opting in is one line per type:

#include <artpp/psio_codec.hpp>

struct point { double x, y; };
PSIO_REFLECT(point, x, y)
ARTPP_PSIO_KEY(point)

artpp::map<point, std::string> m;   // ordered by (x, y), numerically
ARTPP_PSIO_KEY(double)
artpp::map<double, int> d;          // doubles as keys, numeric order

The opt-in is per type so the built-in codecs (zero-copy string views, single-byteswap integrals) keep their faster scratch-free paths.

The adapter needs what psio needs: C++23 and the Boost headers (Boost.Preprocessor, for PSIO_REFLECT). The rest of the library stays C++20 with no dependencies. The adapter and its test are not built in CI.

API reference

map is move-only (copying a large tree is never an accident; to copy, iterate and insert into a new map — there is no range constructor). All operations below are O(encoded-key-length) unless noted. key parameters take the Key type; cheap keys (string_view, integers) pass by value.

Modifiers

Member Semantics Returns
insert(key, v) / upsert(key, v) / insert_or_assign(key, v) Insert, or assign over the existing value (all three are the same operation; insert deliberately follows ART convention rather than std::map::insert's no-overwrite rule — use emplace for that). bool — true iff newly inserted
emplace(key, args...) / try_emplace(key, args...) Insert only if absent. The value is constructed from args exactly once, at its final address; when the key is present, nothing is constructed (stronger than std::map, which may construct and discard). bool — true iff inserted
update(key, v) Assign only if present; never inserts, never restructures. bool — true iff assigned
remove(key) Erase if present. The structure shrinks on the way out (empty routers freed, single-branch routers collapsed, sparse wide nodes de-widened). bool
erase(key) remove with the STL shape. size_type (0 or 1)
erase(pos) Erase the element at a dereferenceable iterator. Two descents (the key is captured, then the successor re-sought). const_iterator to the next element
clear() Destroy every value, free every node. noexcept. —

Overwrites use T's assignment operator (insert_or_assign semantics), not destroy-and-reconstruct, so a throwing assignment leaves a valid object behind.

Lookup

Member Semantics Returns
find(key, T& out) Copy the value out. The direct lookup: one descent, no iterator state, inlined into the caller. (Copy-out, not a pointer, because small values may live inline in the handle bits.) bool
find_opt(key) Copy-out as an optional. std::optional<T>
find(key) STL shape. const_iterator
contains(key) Presence test; never reads the value (cheaper than find for allocating T). bool
count(key) contains with the STL shape. size_type (0 or 1)
at(key) Reference access; throws std::out_of_range if absent. Non-inline T only. T& / const T&
find_ptr(key) Reference access without the throw. Non-inline T only. T* / const T* (null if absent)
operator[](key) Access, default-inserting if absent. Non-inline, default-constructible T only. T&
lower_bound(key) / upper_bound(key) First element >= key / > key in encoded-byte order. const_iterator
equal_range(key) {lower_bound, upper_bound} — at most one element apart (keys are unique). pair of iterators

Traversal

Member Semantics
begin() / end() / cbegin() / cend() Bidirectional const iteration in ascending key order. begin() does not allocate unless the first element is more than 16 nodes deep.
rbegin() / rend() (+cr forms) The same in descending order, through the container's own const_reverse_iterator (see Iterators).
for_each(f) Recursive visitor f(std::string_view key_bytes, const T&) in ascending order, with no per-element resumption (not benchmarked in the suite).
for_each_value(f) f(const T&) in ascending key order without materializing keys.

Capacity, comparison, management

Member Semantics
size() / empty() Element count, noexcept.
max_size() Theoretical bound.
get_allocator() The allocator.
swap(other) / ADL swap O(1) handle swap. Allocators swap iff propagate_on_container_swap; otherwise they must compare equal (standard rule).
operator== / operator!= Content equality, compared structurally — node against node, prefixes and edge directories memcmp'd, no keys materialized. Falls back to an element-wise sweep only when equal-content trees have divergent shapes (possible after removals; see source). T must be equality-comparable only if used.
debug_stats() Node-type census and depth diagnostics (dbg_counts).

Iterators

const_iterator (and iterator, an alias — the container is read-only through iterators) is a bidirectional proxy iterator:

  • iterator_category is std::bidirectional_iterator_tag in the legacy sense; like std::vector<bool>::iterator, operator* returns a proxy (std::pair<Key, const T&> — the key is not stored as an object, it is decoded on demand from the path bytes), so it does not model the C++20 std::bidirectional_iterator concept. Range-for and the classic algorithms (std::distance, std::find_if, std::prev, …) work.
  • What an iterator hands out lives as long as the iterator stays put. An owning key (std::string, an integer, a struct) is a copy and is yours. A std::string_view key — from *it, it->first, it.key() or it.key_bytes() — views the iterator's key buffer, and a reference to a small inline value (below) refers to the copy the iterator holds: both are valid until that iterator is advanced or destroyed. Copy the key (std::string(it.key())) to keep it longer.
  • rbegin() / rend() return the container's own const_reverse_iterator (reverse_iterator is an alias), for map and for set. It holds the iterator positioned on the element, so the rule above applies to it unchanged: *r, r->, r.key(), r.key_bytes() and r.value() are valid until r is advanced or destroyed. It is bidirectional, works with the classic algorithms, and r.base() has the standard meaning (the iterator one past the element; rbegin().base() == end()). Do not wrap the iterators in std::reverse_iterator yourself: that adaptor dereferences a temporary copy, so a string_view key or an inline value obtained through it dangles.
  • it.key() returns the decoded Key; it.key_bytes() returns the raw encoded bytes (zero-copy when the leaf stores the whole key); it.value() returns const T&. The lifetime rule above applies to all three.
  • Key materialization is adaptive: until key()/key_bytes() is first read, ++/-- do no key bookkeeping at all (value-only scans pay nothing). The first read primes the path; from then on the key is maintained incrementally.
  • --end() seats on the last element (std::map semantics); on an empty tree it stays end(). A default-constructed iterator compares equal to end() of any tree.
  • Equality compares positions structurally — no key comparison.

Invalidation. Any structurally mutating operation (insert, emplace, upsert, remove, erase, clear, operator[] on a missing key) invalidates all iterators, and may invalidate references obtained from at/find_ptr/operator[] whose leaf or bucket was restructured. update, and insert / insert_or_assign / upsert / emplace on a key that is already present, never restructure — no node is allocated, freed or moved — so iterators and references stay valid, in every mode; but note an iterator positioned on a small inline value holds a copy made when it was positioned and will not observe later updates; non-inline values are always read live. The safe rule: re-acquire after mutation.

Element access and inline values

A value that is trivially copyable and no larger than inline_cap (sizeof(handle) - 1; 5 bytes with the default 6-byte handle) is stored in the pointer bits of its branch — zero allocation, zero indirection. Such values have no addressable object, so the by-reference API (at, find_ptr, operator[]) is constrained away at compile time (requires-clauses); use the copy-out forms (find(key, out), find_opt) instead. map<K,T>::inlineable reports the decision; uint32_t inlines, uint64_t does not. That is with the default handle: under line_pool's 4-byte handle the cap is 3 bytes, so a uint32_t is a real object there and the reference API is available.

For everything else — strings, 8-byte integers, your structs — values are real objects constructed through the allocator inside leaf (or bucket) storage, and the reference API hands out genuine T& with the invalidation rule above.

Whole-tree operations

Whole-tree work follows one principle: operate on the structure, not the elements.

  • Move construction always steals the root — O(1), noexcept (if the allocator's move is).
  • Move assignment picks the cheapest sound transport, in order:
    1. Steal — allocator propagates (POCMA) or compares equal: O(1).
    2. Image adoption — index-based allocators that opt in (artpp_adopt, e.g. pool_alloc) with trivially-copyable T: the source pool's used range is copied with one memcpy and every handle, including the root, stays valid verbatim, because handles are base-relative line indexes.
    3. Structural clone — raw-pointer allocators: the tree is rebuilt node by node (allocate, memcpy the node, re-point child handles at cloned children; values move-construct object-by-object). Same shape as the source, no descents, no per-key re-insertion.
  • Equality walks both trees node-against-node as described above.
  • Destruction / clear walks once, destroying values and freeing nodes through the allocator — nothing is leaked even after exceptions (verified by fault-injection tests).

Allocators

map is allocator-aware in the standard sense: nodes are 128-byte-aligned block runs taken from a rebound copy of your allocator, values are constructed and destroyed via allocator_traits, and the container honors the propagation traits on move, swap, and assignment. PMR works as expected.

The rebound allocator must honour the alignment of the type it is asked for: 128 bytes for nodes and max(16, alignof(T)) for leaves (std::allocator and PMR do; a malloc-backed allocator that ignores alignof does not). The tree checks every block it receives — alignment, and that the address fits the handle — and throws artpp::bad_allocation_address (derived from std::bad_alloc) after returning the block, so a non-conforming allocator is reported on the first allocation rather than corrupting the tree. The check is on the allocation path only; lookups are unaffected.

Beyond the standard protocol, an allocator can customize the tree through opt-in members (detected, never required):

Member Effect
using artpp_handle = artpp::packed_ptr_t<N>; Selects the branch-handle width. Default is the 6-byte packed pointer (48-bit VA); packed_ptr_t<8> stores full pointers and drops the VA assumption.
using artpp_handle = artpp::detail::line_ptr; + artpp_base() + artpp_term_base() Index-based handles: a 4-byte handle holding a 28-bit line index resolved against artpp_base() (nodes) or a 16-byte-aligned offset resolved against artpp_term_base() (leaves; the two may be the same address). Branches cost 4 bytes and the whole store becomes one relocatable range.
artpp_adopt(const A& src) Opts into bulk image adoption for cross-pool move assignment (see above). Providing it asserts the pool backs exactly one tree.

artpp::line_pool

artpp/pool.hpp ships the reference index-based allocator: two contiguous reservations — 128-byte node lines (up to 32 GB) and 16-byte terminal units for leaves (up to 4 GB, one eighth of the node capacity) — addressed by 4-byte handles, committed in 4 MB steps, with exact-size free lists. It can be anonymous or file-backed:

artpp::line_pool                pool;                       // anonymous memory
artpp::line_pool                disk("mystore");              // file-backed: a store DIRECTORY
using A = artpp::pool_alloc<uint64_t>;
artpp::map<std::string_view, uint64_t, artpp::mode::none, A> t{A{&pool}};

File backing is two things at once: out-of-core storage (page eviction, larger-than-RAM data sets) and a store that survives a clean close and reopen. A file-backed pool is a directory with one dense file per address region — nodes (128-byte lines) and terms (16-byte terminal units), each behind a 64 KB header. One file per region means each grows densely from offset 0 — no sparse files, no 32 GB logical size, no dependency on sparse-file support. Reopening restores the image with no relocation: handles are offsets, so the bytes already are the tree.

using Map = artpp::map<std::string_view, uint64_t, artpp::mode::none, A>;
{
   artpp::line_pool pool("mystore");     // open or create the store directory
   Map t{A{&pool}, artpp::attach};       // the checkpointed tree; empty on a new store
   t.insert("key", 42);
   t.checkpoint();                       // record the tree as the store's content
}                                        // the map and the pool close; the tree stays
{
   artpp::line_pool pool("mystore");     // a later run: pool.restored() == true
   Map t{A{&pool}, artpp::attach};       // O(1), no rebuild
   uint64_t v;
   t.find("key", v);                     // == 42
}

Lifecycle

open → attach → use → checkpoint() → close.

  1. line_pool pool(dir) opens the store in dir, or creates one if there is none (no files, or two empty ones). It takes an exclusive lock for as long as the pool lives. pool.restored() says whether a checkpointed tree was found.
  2. Map t{alloc, artpp::attach} binds a map to that tree in O(1) — or to an empty tree, on a store that was never checkpointed.
  3. t.checkpoint() records the tree as the store's content. By default it forces nothing to disk; see Sync level. What a later open sees is what the last checkpoint() recorded.
  4. Close by destroying the map and the pool, in that order. Destroying a map of a trivially destructible mapped type never tears down a tree in a file-backed pool: the tree belongs to the store, so the destructor leaves it in place (and is O(1)). It does not matter whether the map is destroyed before or after the checkpoint. clear() is how to give a tree's space back to the pool.

Rules that follow from this:

  • Checkpoint last. If the tree is changed after the last checkpoint() and the store is closed — or the process dies — the image is neither the old tree nor the new one, and the next open refuses it (artpp::store_dirty). There is no way to open such a store; pool.dirty() tells you beforehand whether you are in that state. A store that was never checkpointed is the exception: it has nothing to lose and reopens empty.
  • One store, one tree, one map type. The store remembers which instantiation wrote it, and attaching another is refused. Other maps may use the same pool as scratch space; clear() them before the last checkpoint (a scratch map that is destroyed with content leaves its nodes allocated in the store, and one destroyed after the checkpoint marks the store as modified).
  • attach and checkpoint() need a trivially copyable mapped type: the image stores its bytes. (A map whose mapped type has a non-trivial destructor can still use a file-backed pool as out-of-core memory; its destructor destroys the values and frees the nodes. A mapped type that is trivially destructible but not trivially copyable is left in place like any other and cannot be attached: clear() such a map before destroying it.)
  • line_pool is neither copyable nor movable; a map on it moves as usual and takes the tree, and the right to checkpoint it, along.
  • pool.close() does what the pool's destructor does and reports a failure, which a destructor cannot. It does not checkpoint.

pool.checkpoint(root, count) with map::root_handle() / size(), the four-argument attach constructor and detach() are the low-level calls underneath. Prefer the calls above: checkpoint(root, count) records which map type the tree belongs to only if a map attached in the same session. detach() is needed only to hand a tree over within an anonymous pool.

What is checked on open

An existing store is validated before anything is mapped or written; a store that fails is left byte for byte as it was, and nothing is created beside it.

Refused with When
artpp::store_corrupt Not a store, or not a whole one: a foreign file, a missing, empty or truncated file (sizes are checked against what the checkpoint committed), a superblock field outside the range the others allow (capacities, committed sizes, frontiers, free-list heads, the root handle), or nodes and terms that are not from the same store and the same checkpoint.
artpp::store_incompatible A store this program cannot use: another format version, byte order, line size, handle layout or superblock layout; a header reservation the system's page size cannot map; or — thrown by attach — a different map instantiation: size or alignment of the mapped type, mode, handle width, map versus set, or key encoding.
artpp::store_dirty Modified after its last checkpoint (see above).
artpp::store_locked Open in another line_pool, in this process or another (flock).
std::system_error A system call failed (open, mmap, ftruncate, flock, msync, …); it carries the errno and names the file.

The first four derive from artpp::store_error, a std::runtime_error, and name the store and the reason in what(). While a pool is in use, running out of space throws artpp::pool_exhausted and a failure of the system to grow it artpp::pool_commit_failed (with the errno); both are std::bad_alloc, so the tree's exception guarantees apply.

Sync level

checkpoint() takes an artpp::sync_level, on the map and on the low-level pool.checkpoint(root, count, level):

Level What it does Cost Survives
sync_level::none (default) Records the image through the shared file mapping; the operating system writes it back when it chooses. Writing two headers. The process exiting or being killed. Not the machine crashing or losing power before the write-back. A write error (full disk, I/O error) is not reported.
sync_level::flush Writes the data, then the headers, with msync(MS_SYNC), each step checked. Grows with what changed since the previous flush. As above, plus a machine crash after checkpoint() returns, as far as the system honours msync. A write error is thrown from checkpoint() as std::system_error.
t.checkpoint();                          // default: nothing forced to disk
t.checkpoint(artpp::sync_level::flush);  // written out; write errors reported

Neither level is crash consistency: the image is updated in place, so a crash during a checkpoint can leave a store that is refused.

What is not guaranteed

  • No crash durability. This is clean-close persistence: there is no write-ahead log and the image is updated in place. A crash of the process after a change leaves a store that is refused (store_dirty), not one that is recovered; a crash of the machine, or power loss, can lose or damage anything written since the last flushed checkpoint (sync_level::flush; the default forces nothing to disk), and — because msync does not force a drive's write cache on every system — possibly that checkpoint as well. Keep a copy if the data matters.
  • The on-disk format is specific to the library version. A store is only guaranteed to open with the version of the library that wrote it. The format version and the layout parameters are stamped and checked, so an incompatible store is refused rather than misread, but there is no migration.
  • Not everything can be checked. Validation reads the two headers, not the data: damage inside the node or terminal data, or inside a free list, is not detected. The stamp cannot tell apart two mapped types of the same size and alignment (uint64_t and double), nor two user key codecs that do not name their encoding (give a codec a static constexpr std::uint64_t image_id and it can; the built-in codecs have one). A value overwritten in place after the last checkpoint (insert_or_assign on a present key, a write through a reference) changes no structure and is not noticed: it is simply part of the image.
  • The lock is advisory. It keeps a second line_pool out, not other programs; copy a store only while no pool has it open.
  • A store can be moved between machines of the same byte order with 4, 16 or 64 KB pages. It has not been run on a 64 KB-page kernel.

Limits and guarantees

  • Key length — at most max_key_bytes = 65535 encoded bytes (the node formats use 16-bit length fields). The inserting operations (insert, insert_or_assign, upsert, emplace, try_emplace, operator[]) throw std::length_error before any allocation or structural change; update, erase / remove and lookups of a longer key simply miss (no stored key can be that long), keeping the hot path free of the check.

  • Value alignment — alignof(T) up to 128 is supported. Up to 16 costs nothing; above that, leaves are allocated in alignof(T)-sized, alignof(T)-aligned units through the rebound allocator, which must honour that alignment (std::allocator and std::pmr::polymorphic_allocator do). alignof(T) > 128, or alignof(T) > 16 with a line_pool allocator (its terminal region is 16-byte granular), is rejected at compile time.

  • line_pool capacity — 2^28 node lines (32 GB) and 2^28 terminal units (4 GB) at most, or what the pool was constructed with (the terminal region is one eighth of the node capacity). Every leaf that is not stored inside its router's line takes terminal units, so on large maps of long keys or large values the 4 GB terminal region is the limit that is reached first; the allocating operation then throws artpp::pool_exhausted.

  • Stack use — a tree can be as deep as its longest key: keys a, aa, aaa, … build one level per byte, up to 65,535. Depth costs heap, not stack, for every operation, in every mode: find / contains / insert / emplace / update / erase (loops), iterators and lower_bound / upper_bound (heap-backed descent stack), clear and the destructor (constant stack, no allocation), move assignment between unequal allocators and the diagnostic debug_stats() (heap work lists). for_each, for_each_value and operator== recurse for the first 64 levels and hand anything deeper to the iterator: at most about 13 KB of stack in an optimized build, about 100 KB unoptimized.

  • Exception safety — an operation that throws leaves the container valid and leaks nothing: no node, and no value's destructor skipped or run twice. In every mode:

    • insert, insert_or_assign, upsert, emplace, try_emplace and operator[] are strong: if one throws (bad_alloc, or an exception from T's constructors), the contents are exactly what they were — every key and every value. An rvalue passed to insert may have been moved from.
    • erase(key) / remove and clear do not throw. The steps of an erase that allocate (collapsing a router, repacking a bucket) are best-effort: if one fails the key is still removed and the tree is merely less compact. (erase(key) is not declared noexcept only because a user-supplied key codec may throw while encoding the key. erase(pos) never fails through the tree's allocator either, but it copies the key and builds the iterator it returns, which for long keys and deep trees takes memory from the global heap.)
    • Move assignment between unequal allocators gives the basic guarantee: if the clone fails, the target is empty, and the source keeps all its keys, with values that are not trivially copyable possibly moved-from.
    • One documented exception to "strong", in mode::buckets and mode::adaptive only: a mapped type that is move-only and has a throwing move constructor. Existing values are relocated when a bucket overflows or a leaf is collapsed into one; the tree moves them if the move cannot throw and copies them otherwise (the std::vector rule), so nothing is lost. A type that can do neither keeps all its keys if such a move throws, but values already moved are left moved-from.

    What is tested (artpp_exception_safety): random sequences of insert, insert_or_assign, emplace, operator[], erase by key and by iterator, clear and cross-allocator move over clustered, nested and oversized keys, repeated once per fault point — the allocator failing at each allocation in turn, and T's constructors throwing at each construction in turn — and, on further sequences twice as long, with every 2nd, 3rd, 5th, 7th and 13th one failing. After each failure the contents are compared with a std::map oracle, and at the end blocks and live values must balance. This runs in mode::buckets and mode::adaptive for 8-byte, in-handle (4-byte), 120-byte, std::string, throwing-copy and move-only mapped types, and for a sample of those types combined with dense_tiers, dense_tiers | ladder_c8 and wide_stems; each run injects either allocation or constructor failures (both for the move-only type); in the default, dense_tiers and wide_stems modes for a sample of the types; and for artpp::set. The paths the audit named (router widening, bucket overflow, bucket repacking on erase, leaf-to-bucket collapse) have their own sweeps on top. Limits of the testing: wide (setlist_u16) nodes hardly occur in these sequences; their creation and re-striding are fault-tested by a bulk-insert sweep that checks validity and leaks rather than contents, and erase and cross-allocator move are not fault-tested on a tree that holds one. line_pool is not put through the systematic sweep (artpp_pool_safety checks a map that runs its pool dry); key codecs that throw are not fault-tested.

  • Thread safety — that of a standard container: concurrent reads on a const tree are fine; any write requires exclusive access. No internal threads, no locks.

  • Ordering — strictly ascending encoded-byte order; with the integral codecs this is exact numeric order, including negatives.

  • The container is move-only; copy construction/assignment are deleted by design.

Performance

Measured 2026-11-28 on the release code (390e25c), on two machines:

  • M5: Apple M5 Max, macOS 26.3, Apple clang 17, -O3. The machine was in use: load averages were 2.4–4.8 during the main suite; the three 32-byte-key runs started at 2.9, 44.2, 2.9.
  • x86: AMD EPYC-Turin virtual machine (16 vCPUs), x86-64 Linux, clang++ 20, libstdc++ 15, -O3, pinned to one core; load average under 2.5.

The main suite (artpp_bench) ran 7 times on each machine. An absolute time is the median of the 7 runs; a "times faster" figure is the median of the per-run ratios (baseline time / artpp time, both from the same run). Above 1 is faster than the baseline, below 1 is slower. Where the runs differ by more than 10 % of the median, the range over the runs follows in parentheses. The 32-byte-key and set benchmarks ran fewer times (3 on the M5, 2 on the x86 server) and report the minimum over the runs, because one M5 run started under a load average of 44.

The raw output of every run is in docs/bench/2026-11-28; the medians are docs/results-m5.csv and docs/results-x86.csv; python3 docs/bench/2026-11-28/summary.py regenerates those files, the charts on the website and every table and figure in this section from the raw output. Workloads: dictionary words (each machine's own /usr/share/dict/words: 236k words on the M5, 104k on the x86 server, so the dictionary rows compare the contestants on one machine and not the two machines with each other), 885k clustered strings, 1M uniform random and 1M sequential uint64_t.

Point lookups

Point lookups of present keys, in random order. ns is artpp's time per lookup; the other columns say how many times faster artpp is than each baseline.

workload allocator M5 ns M5 vs libart M5 vs absl::btree_map M5 vs std::map x86 ns x86 vs libart x86 vs absl::btree_map x86 vs std::map
dictionary words line_pool 110 (103–119) 1.14× (1.04–1.18) 1.80× 2.19× (1.88–2.44) 87.8 1.11× 2.42× 2.73×
std::allocator 111 1.14× 1.72× (1.66–2.00) 2.15× (2.07–2.32) 91.7 1.06× 2.33× 2.63×
clustered strings line_pool 129 1.35× 2.42× 3.85× (3.61–4.14) 320 (320–356) 1.05× (0.95–1.06) 3.02× (2.77–3.08) 4.33× (3.92–4.39)
std::allocator 129 (126–141) 1.34× 2.37× 3.83× (3.65–4.04) 351 0.96× 2.80× 3.96×
uniform u64 line_pool 41.5 1.27× 2.20× (2.04–2.64) 4.68× 107 (106–143) 0.78× (0.61–0.82) 1.02× (0.76–1.05) 2.09× (1.59–3.24)
std::allocator 43.2 1.24× 2.13× (2.00–2.64) 4.54× (4.46–4.93) 127 (123–137) 0.68× (0.61–0.70) 0.87× (0.80–0.89) 1.79× (1.71–2.54)
sequential u64 line_pool 24.4 (23.7–26.9) 1.97× 3.13× (2.92–3.45) 6.83× (6.28–7.03) 28.3 (27.4–42.7) 3.49× (2.44–3.83) 3.47× (2.31–3.64) 8.05× (5.28–9.17)
std::allocator 33.1 (31.3–36.8) 1.44× (1.34–1.55) 2.40× (2.21–2.53) 5.03× (4.60–5.43) 69.1 1.44× 1.43× 3.29× (3.26–3.64)

Where artpp is slower (every cell below 1 in the table):

  • Lookups (hit) against libart: Apple M5 Max: none; AMD EPYC-Turin: clustered strings (0.96× std::allocator); uniform u64 (0.78× line_pool, 0.68× std::allocator).
  • Lookups (hit) against absl::btree_map: Apple M5 Max: none; AMD EPYC-Turin: uniform u64 (0.87× std::allocator).
  • Lookups (hit) against std::map: Apple M5 Max: none; AMD EPYC-Turin: none.

On the x86-64 server artpp is slower than libart on uniform random integers and about level with it on the two string workloads; on the M5 it is faster in every row. The cause of the difference between the machines is not yet known (huge pages were tried on the x86-64 server and did not help). On uniform random integers line_pool lookups run at 1.03× the speed of the std::allocator map on the M5 and 1.18× on the x86-64 server: line_pool is not slower on uniform keys on either machine.

Other operations

The other operations, per machine. ns is artpp's time per operation (per element for scans); the ratio columns say how many times faster artpp is. libart has no lower_bound. Scans are full in-order traversals (artpp through for_each_value, libart through art_iter, the other two through their iterators); erase removes every other key.

Apple M5 Max

op workload line_pool ns vs libart vs absl::btree_map std::allocator ns vs libart vs absl::btree_map
inserts dictionary words 94.9 0.87× 0.78× 118 0.70× 0.63×
clustered strings 170 (161–195) 1.14× (1.02–1.22) 1.57× (1.46–1.70) 198 (187–213) 0.99× (0.87–1.12) 1.35× (1.30–1.51)
uniform u64 48.1 (46.2–54.8) 1.15× (0.99–1.80) 1.97× (1.81–2.04) 58.9 (56.4–97.7) 0.91× (0.58–1.63) 1.61× (0.96–1.85)
sequential u64 10.4 (9.8–12.6) 1.91× (1.56–1.93) 2.78× (2.31–3.03) 14.2 1.39× 2.05×
misses dictionary words 39.0 1.32× 2.13× 40.7 1.26× 2.04×
clustered strings 97.7 1.26× 2.87× (2.74–3.08) 98.4 1.25× 2.84× (2.70–3.00)
uniform u64 16.2 1.20× (1.18–1.31) 5.52× (5.24–6.11) 18.0 1.09× (1.06–1.23) 4.97× (4.80–5.73)
sequential u64 5.3 1.30× 5.02× 5.6 (5.0–6.0) 1.24× (1.13–1.37) 4.76× (4.52–5.35)
lower_bound dictionary words 82.5 n/a 0.96× 86.6 n/a 0.91×
clustered strings 203 (198–224) n/a 1.33× (1.26–1.41) 203 (199–225) n/a 1.33× (1.26–1.41)
uniform u64 102 (99.5–114) n/a 0.89× (0.86–1.00) 108 (105–116) n/a 0.87× (0.80–0.97)
sequential u64 16.5 n/a 1.67× 17.0 n/a 1.61×
ordered scans dictionary words 8.4 0.75× 0.12× (0.12–0.13) 8.1 0.77× 0.13× (0.11–0.13)
clustered strings 18.4 0.88× 0.50× (0.49–0.56) 19.1 0.84× 0.49×
uniform u64 15.8 0.86× 0.15× (0.15–0.17) 19.4 0.71× 0.13× (0.12–0.14)
sequential u64 1.6 1.04× 0.41× 2.0 0.86× 0.35×
erases dictionary words 209 (186–224) 0.90× (0.88–1.00) 1.11× (1.04–1.44) 218 (208–234) 0.86× (0.80–0.93) 1.05× (0.96–1.30)
clustered strings 287 (276–322) 0.96× 1.14× (1.09–1.25) 287 (271–326) 0.97× 1.15× (1.07–1.25)
uniform u64 120 (116–129) 1.10× (1.04–1.15) 0.92× (0.83–1.07) 135 (131–275) 0.97× (0.51–1.01) 0.81× (0.43–0.86)
sequential u64 72.5 (65.6–81.0) 1.34× (1.10–1.56) 1.40× (1.12–1.58) 81.0 (78.5–87.6) 1.14× (1.07–1.29) 1.18× (1.12–1.29)

AMD EPYC-Turin

op workload line_pool ns vs libart vs absl::btree_map std::allocator ns vs libart vs absl::btree_map
inserts dictionary words 97.9 0.74× 1.19× 142 (141–156) 0.51× (0.46–0.52) 0.82× (0.74–0.86)
clustered strings 382 (348–422) 0.92× (0.81–1.16) 2.92× (2.61–3.19) 501 (462–529) 0.72× (0.68–0.81) 2.21× (2.08–2.42)
uniform u64 70.6 (65.6–91.9) 1.46× (1.11–1.65) 1.72× (1.34–1.87) 83.1 (83.0–111) 1.22× (0.95–1.30) 1.47× (1.10–1.49)
sequential u64 18.1 (17.9–26.9) 1.81× (1.23–1.88) 2.34× (1.58–2.48) 21.1 1.55× 1.99× (1.92–2.13)
misses dictionary words 35.5 1.19× 2.90× 39.0 1.09× 2.65×
clustered strings 198 (195–239) 0.66× (0.55–0.70) 4.65× (3.93–4.75) 274 0.49× (0.46–0.51) 3.37×
uniform u64 23.4 (22.9–31.0) 0.80× (0.61–0.91) 4.61× (3.50–5.07) 29.3 (28.8–35.1) 0.64× (0.59–0.74) 3.73× (3.31–3.80)
sequential u64 8.5 0.87× 3.45× 9.2 0.81× 3.19×
lower_bound dictionary words 83.8 n/a 1.21× 85.0 n/a 1.19×
clustered strings 363 n/a 2.52× 553 (544–612) n/a 1.65×
uniform u64 181 (179–198) n/a 0.62× 226 (223–271) n/a 0.49× (0.41–0.50)
sequential u64 21.5 n/a 1.31× 25.1 n/a 1.12×
ordered scans dictionary words 8.5 0.98× 0.24× 9.0 0.93× 0.22× (0.22–0.24)
clustered strings 38.5 (38.2–56.4) 1.01× (0.69–1.12) 0.64× (0.44–0.75) 48.6 (48.3–72.3) 0.80× (0.60–0.81) 0.51× (0.33–0.60)
uniform u64 51.4 (50.9–61.4) 0.85× (0.77–0.93) 0.06× (0.05–0.07) 61.2 0.72× (0.68–0.77) 0.05× (0.05–0.06)
sequential u64 2.5 2.49× 0.69× (0.65–0.96) 6.8 0.91× 0.26× (0.24–0.35)
erases dictionary words 135 (131–188) 0.95× (0.75–1.23) 1.90× (1.47–2.12) 164 (160–260) 0.79× (0.49–0.99) 1.51× (1.06–1.84)
clustered strings 493 (478–547) 1.02× (0.94–1.08) 2.15× (1.95–2.25) 669 (632–749) 0.77× (0.68–0.80) 1.59× (1.43–1.70)
uniform u64 292 (286–336) 0.99× (0.90–1.02) 0.48× (0.40–0.51) 372 0.78× (0.73–0.84) 0.37× (0.34–0.40)
sequential u64 65.3 (63.6–81.2) 2.02× (1.66–2.34) 1.82× (1.46–1.95) 192 (191–227) 0.68× (0.57–0.77) 0.62× (0.52–0.65)

Where artpp is slower (every cell below 1 in the two tables):

  • Inserts against libart: Apple M5 Max: dictionary words (0.87× line_pool, 0.70× std::allocator); clustered strings (0.99× std::allocator); uniform u64 (0.91× std::allocator); AMD EPYC-Turin: dictionary words (0.74× line_pool, 0.51× std::allocator); clustered strings (0.92× line_pool, 0.72× std::allocator).
  • Inserts against absl::btree_map: Apple M5 Max: dictionary words (0.78× line_pool, 0.63× std::allocator); AMD EPYC-Turin: dictionary words (0.82× std::allocator).
  • Misses against libart: Apple M5 Max: none; AMD EPYC-Turin: clustered strings (0.66× line_pool, 0.49× std::allocator); uniform u64 (0.80× line_pool, 0.64× std::allocator); sequential u64 (0.87× line_pool, 0.81× std::allocator).
  • Misses against absl::btree_map: Apple M5 Max: none; AMD EPYC-Turin: none.
  • lower_bound against absl::btree_map: Apple M5 Max: dictionary words (0.96× line_pool, 0.91× std::allocator); uniform u64 (0.89× line_pool, 0.87× std::allocator); AMD EPYC-Turin: uniform u64 (0.62× line_pool, 0.49× std::allocator).
  • Ordered scans against libart: Apple M5 Max: dictionary words (0.75× line_pool, 0.77× std::allocator); clustered strings (0.88× line_pool, 0.84× std::allocator); uniform u64 (0.86× line_pool, 0.71× std::allocator); sequential u64 (0.86× std::allocator); AMD EPYC-Turin: dictionary words (0.98× line_pool, 0.93× std::allocator); clustered strings (0.80× std::allocator); uniform u64 (0.85× line_pool, 0.72× std::allocator); sequential u64 (0.91× std::allocator).
  • Ordered scans against absl::btree_map: Apple M5 Max: dictionary words (0.12× line_pool, 0.13× std::allocator); clustered strings (0.50× line_pool, 0.49× std::allocator); uniform u64 (0.15× line_pool, 0.13× std::allocator); sequential u64 (0.41× line_pool, 0.35× std::allocator); AMD EPYC-Turin: dictionary words (0.24× line_pool, 0.22× std::allocator); clustered strings (0.64× line_pool, 0.51× std::allocator); uniform u64 (0.06× line_pool, 0.05× std::allocator); sequential u64 (0.69× line_pool, 0.26× std::allocator).
  • Erases against libart: Apple M5 Max: dictionary words (0.90× line_pool, 0.86× std::allocator); clustered strings (0.96× line_pool, 0.97× std::allocator); uniform u64 (0.97× std::allocator); AMD EPYC-Turin: dictionary words (0.95× line_pool, 0.79× std::allocator); clustered strings (0.77× std::allocator); uniform u64 (0.99× line_pool, 0.78× std::allocator); sequential u64 (0.68× std::allocator).
  • Erases against absl::btree_map: Apple M5 Max: uniform u64 (0.92× line_pool, 0.81× std::allocator); AMD EPYC-Turin: uniform u64 (0.48× line_pool, 0.37× std::allocator); sequential u64 (0.62× std::allocator).

In short: artpp inserts dictionary words more slowly than libart on both machines, and its default-mode scans are slower than absl::btree_map's in every cell; integer inserts with line_pool are faster than libart's on both machines. The same tree on line_pool instead of std::allocator inserts 1.14–1.37× as fast on the M5 and 1.17–1.45× on the x86-64 server, and looks up 1.00–1.37× and 1.04–2.46× as fast.

Bucket mode

mode::buckets on the line_pool, against the default mode on the same allocator ("vs default mode": above 1 means buckets are faster) and against the baselines:

workload machine hit ns vs default mode vs libart scan ns/element vs default mode vs absl::btree_map
dictionary words M5 94.6 (89.2–101) 1.19× (1.08–1.20) 1.35× (1.23–1.42) 2.7 3.10× (2.82–3.18) 0.37× (0.33–0.40)
x86 82.0 1.07× 1.19× 3.2 2.62× 0.62×
clustered strings M5 169 (162–180) 0.76× 1.04× 8.6 2.15× 1.10× (1.06–1.19)
x86 376 0.86× (0.84–0.95) 0.89× 15.7 2.49× (2.45–3.51) 1.57× (1.54–1.88)
uniform u64 M5 42.1 1.00× 1.28× (1.21–1.39) 3.8 (3.5–4.0) 4.21× (3.95–4.48) 0.67× (0.59–0.71)
x86 68.8 (68.1–89.9) 1.56× 1.25× (0.96–1.28) 6.0 (5.9–8.1) 8.65× (6.31–10.05) 0.55× (0.45–0.58)
sequential u64 M5 54.4 (50.7–56.5) 0.46× (0.43–0.48) 0.90× 9.1 0.18× 0.08×
x86 161 0.18× (0.17–0.27) 0.62× 20.1 0.12× 0.09× (0.08–0.12)

On dictionary words, on both machines, bucket mode looks up 1.07–1.19× as fast as the default mode and scans 2.62–3.10× as fast; on clustered strings its scans are 1.10–1.57× absl::btree_map's. On dictionary words its scans are still slower than absl::btree_map's, and on sequential integers bucket mode is slower than the default mode at both lookups and scans.

32-byte keys

Random 32-byte keys (hashes, UUIDs, composite keys), 10M of them, each container built and measured on its own (bench/bench_buffer.cpp; unodb on the identical keys with bench/bench_buffer_unodb.cpp, as unodb::db<unodb::key_view, std::uint64_t>). Minimum over the runs (3 on the M5, 2 on the x86 server); scan is per element. art_map is not in the table: the benchmark source records that it does not compile for a key longer than 16 bytes.

ns per op M5 insert M5 hit M5 scan M5 lower_bound x86 insert x86 hit x86 scan x86 lower_bound
artpp::map (line_pool) 111.6 68.2 17.15 119.6 235.9 211.4 59.72 361.2
artpp::map (std::allocator) 152.0 68.3 18.13 127.8 381.3 216.9 55.04 380.5
libart 140.4 92.8 13.03 n/a 665.3 163.4 41.99 n/a
unodb 447.2 325.0 212.26 585.9 823.6 920.7 309.24 738.6
absl::btree_map 1040.8 1071.3 10.49 1034.1 1914.0 1888.0 43.33 2049.6
std::map 1378.8 1387.8 72.93 1393.6 2123.7 3274.5 210.11 3377.4
std::unordered_map 202.2 91.7 n/a n/a 1092.9 280.6 n/a n/a

How many times faster artpp is on each operation (below 1 is slower):

artpp allocator times faster than M5 insert M5 hit M5 scan M5 lower_bound x86 insert x86 hit x86 scan x86 lower_bound
line_pool unodb 4.01× 4.77× 12.38× 4.90× 3.49× 4.36× 5.18× 2.04×
libart 1.26× 1.36× 0.76× n/a 2.82× 0.77× 0.70× n/a
absl::btree_map 9.33× 15.71× 0.61× 8.65× 8.11× 8.93× 0.73× 5.67×
std::map 12.35× 20.35× 4.25× 11.65× 9.00× 15.49× 3.52× 9.35×
std::unordered_map 1.81× 1.34× n/a n/a 4.63× 1.33× n/a n/a
std::allocator unodb 2.94× 4.76× 11.71× 4.58× 2.16× 4.24× 5.62× 1.94×
libart 0.92× 1.36× 0.72× n/a 1.74× 0.75× 0.76× n/a
absl::btree_map 6.85× 15.69× 0.58× 8.09× 5.02× 8.70× 0.79× 5.39×
std::map 9.07× 20.32× 4.02× 10.90× 5.57× 15.10× 3.82× 8.88×
std::unordered_map 1.33× 1.34× n/a n/a 2.87× 1.29× n/a n/a

Against unodb artpp is faster on every operation on both machines: lookups 4.76–4.77× (M5) and 4.24–4.36× (x86), inserts 2.94–4.01× and 2.16–3.49×, ordered scans 11.71–12.38× and 5.18–5.62×, lower_bound 4.58–4.90× and 1.94–2.04×. Against libart, lookups are 1.36× on the M5 and 0.75–0.77× on the x86-64 server, where artpp is slower. Ordered scans are slower than libart's and absl::btree_map's on both machines (0.58–0.61× and 0.73–0.79× absl::btree_map).

File-backed, against Boost.MultiIndex in a mapped file

A map on a file-backed line_pool is stored in a file and reopened without a rebuild. The usual way to get an ordered container in a mapped file in C++ is boost::multi_index_container (or another Boost.Interprocess container) allocated in a boost::interprocess::managed_mapped_file, so that is the comparison.

artpp_bench_filebacked (bench/bench_filebacked.cpp) stores the four workloads of the main suite, the same keys in the same order, in a file with each contestant, each in its own new directory:

  • artpp: artpp::map<Key, uint64_t> on a file-backed line_pool, with the documented lifecycle (open, attach, checkpoint()).
  • Boost.MultiIndex: boost::multi_index_container with one ordered_unique index, allocated with boost::interprocess::allocator in a managed mapped file, so elements and index nodes are in the file and linked by offset_ptr. Boost 1.90.0 on the M5 (Homebrew), 1.88.0 on the x86-64 server. The segment is configured without Boost's inter-process mutex (null_mutex_family), since nothing shares it and artpp takes no lock either. String keys are boost::interprocess::basic_string, compared against a std::string_view without constructing a string; keys of up to 22 bytes sit in the string's internal buffer, which is all but 23 (M5) and 1 (x86) of the dictionary words and every clustered key, so Boost makes one allocation per element. The file is created at 1 GiB and is sparse (a managed mapped file cannot grow while it is mapped).

3 runs per machine, one process at a time (load averages before the runs: 1.18, 2.88, 2.19 on the M5, 1.26, 1.68, 1.76 on the x86-64 server); times are the median of the runs and "artpp faster" is the median of the per-run ratios, below 1 meaning slower. The stores were on local disks (APFS on the M5, ext4 on the x86-64 server). The page cache was warm throughout: the benchmark reopens a store moments after writing it, so the reopen figures measure mapping and validation, not reading from disk.

op workload M5 artpp ns M5 Boost.MultiIndex ns M5 artpp faster x86 artpp ns x86 Boost.MultiIndex ns x86 artpp faster
insert dictionary words 95.1 206 2.16× 124 418 3.35×
clustered strings 174 524 3.08× 405 978 2.41×
uniform u64 50.0 465 9.32× 98.6 636 6.05×
sequential u64 10.8 238 22.03× 24.1 356 14.93×
hit dictionary words 111 287 2.63× 87.3 230 2.63×
clustered strings 124 534 4.28× 322 917 2.86×
uniform u64 41.0 476 12.18× 119 595 4.98×
sequential u64 23.3 408 16.99× 27.8 892 31.63×
miss dictionary words 39.5 93.4 2.36× 35.4 91.9 2.60×
clustered strings 96.2 457 4.75× 201 571 2.84×
uniform u64 16.1 467 29.20× 28.1 549 19.62×
sequential u64 5.3 73.2 13.77× 8.7 115 13.24×
lower_bound dictionary words 82.5 84.8 1.03× 81.5 106 1.30×
clustered strings 194 444 2.30× 372 554 1.48×
uniform u64 99.0 488 4.92× 196 554 3.02×
sequential u64 16.6 72.8 4.38× 22.3 114 5.14×
scan dictionary words 8.3 9.8 1.15× 8.3 9.3 1.11×
clustered strings 18.0 100 5.74× 38.9 162 4.17×
uniform u64 15.4 88.2 6.14× 56.0 140 2.49×
sequential u64 1.6 8.0 4.81× 2.3 8.2 3.50×
erase (after reopen) dictionary words 199 554 2.70× 160 598 3.75×
clustered strings 275 1182 4.29× 600 1726 2.88×
uniform u64 123 932 7.55× 326 1410 4.32×
sequential u64 63.6 781 12.28× 113 1559 13.74×
hit after reopen, first pass dictionary words 121 300 2.53× 95.3 237 2.48×
clustered strings 131 593 4.52× 349 893 2.72×
uniform u64 44.6 499 11.53× 124 657 5.65×
sequential u64 32.3 427 13.22× 33.0 900 27.30×
hit after reopen dictionary words 107 265 2.48× 87.3 230 2.61×
clustered strings 122 575 4.73× 317 914 2.88×
uniform u64 40.4 500 12.74× 111 617 5.83×
sequential u64 21.3 417 19.44× 27.8 873 30.97×

"hit after reopen": the store is closed, reopened in the same process with a new line_pool or a new managed-file object, every key is read back and checked against its value (all runs passed for both), and the lookup loop runs again; "first pass" is its first run over the reopened mapping. The erase row runs on the reopened store, so it is not comparable with the erase row of the main suite.

Making the data durable, and reopening it. A range in parentheses is the minimum and maximum over the runs of a one-shot figure:

workload machine artpp checkpoint() µs Boost flush() µs artpp to disk ms Boost to disk ms artpp close µs Boost close µs artpp reopen µs Boost reopen µs
dictionary words M5 0.9 (0.8–1.2) 1411 (1345–4678) 3.11 (3.09–3.23) 1.46 (1.39–4.73) 250 (239–278) 108 (105–152) 130 (113–156) 49 (38–52)
x86 1.6 (1.6–1.6) 2.5 (2.1–2.9) 4.77 (3.52–5.22) 3.31 (3.16–3.96) 446 (114–493) 115 (100–528) 39 (36–48) 30 (27–33)
clustered strings M5 1.1 (0.8–1.2) 4489 (4462–6087) 8.46 (7.71–10.78) 4.66 (4.64–6.20) 390 (390–488) 346 (294–375) 146 (146–147) 59 (58–62)
x86 1.9 (1.8–2.1) 4.1 (3.2–4.2) 19.76 (16.27–21.80) 19.35 (18.89–19.53) 2843 (700–3569) 914 (500–961) 78 (70–94) 35 (35–51)
uniform u64 M5 0.9 (0.9–1.0) 3826 (3747–3892) 9.81 (9.77–9.89) 4.00 (3.97–4.03) 684 (640–733) 343 (312–400) 143 (119–158) 66 (65–66)
x86 2.5 (2.2–3.0) 4.3 (4.0–5.0) 22.43 (19.03–25.38) 17.54 (14.17–18.76) 4295 (838–4335) 966 (904–1022) 75 (62–82) 61 (50–64)
sequential u64 M5 0.9 (0.8–1.2) 3851 (3704–4160) 4.03 (3.88–4.65) 4.04 (3.81–4.48) 374 (352–488) 361 (236–473) 132 (130–141) 53 (48–64)
x86 2.4 (2.3–2.5) 4.6 (3.9–4.7) 12.42 (9.39–12.53) 18.26 (17.40–18.54) 1609 (294–1743) 886 (851–912) 58 (50–76) 43 (39–53)
  • artpp checkpoint() (the default, sync_level::none) records the tree in the store's headers through the mapping and forces nothing to disk: the store survives the process, not a crash of the machine.
  • Boost flush() is msync(MS_ASYNC) (mapped_region::flush with its default async = true): it asks the system to write the mapping back and does not wait for it.
  • To disk is that step plus a synchronous write of the mapping: checkpoint(sync_level::flush) for artpp, which is msync(MS_SYNC) of the data and then of the headers; for Boost an msync(MS_SYNC) of the whole mapping, issued by the benchmark, because the managed file exposes only the asynchronous form. Neither is crash consistency.
  • Close unmaps the store and closes its files (line_pool::close() after destroying the map; the managed file's destructor).
  • Reopen is the time from opening the store to the result of the first lookup: for artpp the line_pool constructor (which validates the store) and attach; for Boost the managed-file constructor and find of the container by name.

Space. "Used" is what the contestant has allocated (for artpp the node lines and terminal units handed out plus the two headers; for Boost the segment size minus get_free_memory()), per key. artpp's two files grow in 4 MB steps; Boost's 1 GiB file is sparse, so its size on disk is what counts:

workload machine keys artpp used B/key Boost used B/key artpp files MiB artpp on disk MiB Boost on disk MiB
dictionary words M5 235,976 84.8 80.0 20.1 20.1 18.0
x86 104,334 84.9 80.0 12.1 8.4 8.0
clustered strings M5 884,615 66.4 80.0 56.1 56.1 67.5
x86 884,615 66.4 80.0 56.1 55.9 68.0
uniform u64 M5 1,000,000 67.0 56.0 68.1 68.1 53.4
x86 1,000,000 66.9 64.0 68.1 63.7 62.0
sequential u64 M5 1,000,000 26.2 56.0 28.1 28.1 53.4
x86 1,000,000 26.2 64.0 28.1 24.9 62.0

For reference, the same artpp map on an anonymous line_pool and boost::interprocess::map (the red-black tree map of Boost.Interprocess) in the same kind of segment. Relative to the map in memory, the file-backed artpp map looks up at 0.89–1.04× the speed and inserts at 0.75–0.99×:

workload machine hit ns: artpp, file hit ns: artpp, memory hit ns: Boost.MultiIndex, file hit ns: boost::interprocess::map, file insert ns: artpp, file insert ns: artpp, memory insert ns: Boost.MultiIndex, file insert ns: boost::interprocess::map, file
dictionary words M5 111 103 287 320 95.1 94.6 206 339
x86 87.3 87.2 230 276 124 96.6 418 383
clustered strings M5 124 123 534 638 174 170 524 568
x86 322 321 917 1049 405 370 978 998
uniform u64 M5 41.0 40.8 476 507 50.0 48.0 465 432
x86 119 106 595 526 98.6 74.3 636 533
sequential u64 M5 23.3 24.0 408 575 10.8 10.1 238 333
x86 27.8 28.4 892 483 24.1 17.9 356 472

Where artpp is behind Boost.MultiIndex (every such cell of the tables above):

  • bytes used per key, artpp larger: M5 dictionary words (84.8 against 80.0 B/key), M5 uniform u64 (67.0 against 56.0 B/key), x86 dictionary words (84.9 against 80.0 B/key), x86 uniform u64 (66.9 against 64.0 B/key).
  • time to disk, artpp longer: M5 dictionary words, M5 clustered strings, M5 uniform u64, x86 dictionary words, x86 clustered strings, x86 uniform u64.
  • close, artpp longer: M5 dictionary words, M5 clustered strings, M5 uniform u64, M5 sequential u64, x86 dictionary words, x86 clustered strings, x86 uniform u64, x86 sequential u64.
  • reopen to first lookup, artpp longer: M5 dictionary words, M5 clustered strings, M5 uniform u64, M5 sequential u64, x86 dictionary words, x86 clustered strings, x86 uniform u64, x86 sequential u64.

In short: against boost::multi_index_container with one ordered index in a Boost.Interprocess mapped file, on the four workloads of the main suite, lookups are 2.63–16.99× faster on the M5 and 2.63–31.63× on the x86-64 server, inserts 2.16–22.03× and 2.41–14.93×, lower_bound 1.03–4.92× and 1.30–5.14×. Boost reopens a store sooner (49–66 µs to the first lookup against artpp's 130–146 µs on the M5; 30–61 µs against 39–78 µs on the x86-64 server), closes it sooner, and needs fewer bytes per key on dictionary words and uniform integers (84.79–84.90 against 80.00–80.01 B/key; 66.88–66.97 against 56.00–64.00 B/key), where artpp needs fewer on clustered strings and sequential integers (66.37–66.39 against 80.00 B/key; 26.17 against 56.00–64.00 B/key). Boost.MultiIndex holds several indexes over one element, which artpp does not.

What each offers that the other does not, from reading both:

  • Boost.MultiIndex in a managed segment holds several indexes over one element (ordered unique and non-unique, hashed, ranked, sequenced, random access), which is the reason to choose it; artpp has one ordered key per map. Its elements can be any type built from offset-pointer-aware parts (Boost.Interprocess strings, vectors and maps inside an element), where artpp's file-backed images need a trivially copyable mapped type. One segment holds any number of named objects; an artpp store holds one tree. managed_mapped_file::grow and shrink_to_fit resize a closed segment. Boost supports MSVC and Windows; artpp is GCC or Clang on a POSIX system.
  • artpp validates a store before using it and refuses one it cannot trust: line_pool's constructor checks the two headers against each other and against the file sizes (validate_ in pool.hpp; the table under What is checked on open), attach compares the stamp of the map instantiation that wrote the image (artpp::store_incompatible), a store modified after its last checkpoint is refused (artpp::store_dirty), and a second opener is locked out. Boost trusts the segment: opening checks the segment's initialization word (managed_open_or_create_impl.hpp), and find<T>(name) looks the object up by name with no check of its type beyond a BOOST_ASSERT on its size (priv_generic_find in segment_manager.hpp), which a release build compiles out. A segment written by another build with a different element layout, or one whose writer died in the middle of an update, is used as it is. artpp's branch handles are 4 bytes; Boost's offset_ptr is 8.
  • Both store positions relative to the mapping, not addresses, so a store can be mapped at another address or by another process: artpp's handles are line indexes from the pool's base (detail::line_ptr in pool.hpp), and Boost's offset_ptr holds the distance from the pointer to its target. In this benchmark every reopen happened to map the store at the address it had before, so relocation was not exercised by these runs.
  • Neither is crash-consistent. artpp's persistence is clean-close only (What is not guaranteed); a Boost segment has no checkpoint at all, so what a crash leaves is whatever had been written.

artpp::set — keys-only ordered set

artpp::set<Key> is the map's value-free sibling — a thin facade over map<Key, none_t> that shares the radix core verbatim, elides the value path, and lets short keys ride entirely inside the routing handle (suffix-in-handle, no leaf allocation). It is measured separately from the tables above, with its own method:

2M keys per key set (1.8M for the short keys), std::allocator behind a counting allocator (not line_pool), find = fastest of 7 passes over a shuffled all-present probe, insert = build time per key (bench/ordered_bench.cpp). Minimum over the runs (3 on the M5, 2 on the x86 server); the factor in parentheses is how many times faster artpp::set finds.

keys machine artpp::set find ns insert ns B/key absl::btree_set find ns insert ns B/key std::set find ns insert ns B/key
random 16 B M5 61.8 66.1 94.3 383.6 (6.21×) 37.1 26.4 992.0 (16.05×) 172.2 56.0
x86 246.6 271.9 94.3 1046.4 (4.24×) 308.5 35.4 2130.1 (8.64×) 573.6 64.0
alphanumeric 16 B M5 71.5 103.8 41.0 373.2 (5.22×) 38.0 26.4 948.0 (13.26×) 161.8 56.0
x86 318.8 291.6 41.0 1090.4 (3.42×) 269.1 35.4 1804.3 (5.66×) 602.8 64.0
short 3–7 B M5 62.0 96.1 26.4 370.6 (5.98×) 52.1 26.4 901.4 (14.54×) 203.9 56.0
x86 161.1 89.6 26.4 627.6 (3.90×) 84.3 35.4 1242.5 (7.71×) 373.2 64.0

artpp::set finds 5.22–6.21× faster than absl::btree_set on the M5 and 3.42–4.24× on the x86-64 server (13.26–16.05× and 5.66–8.64× faster than std::set). Building is a different matter: per key, artpp::set inserts 0.37–0.56× as fast as absl::btree_set on the M5 and 0.92–1.13× on the x86-64 server (below 1 is slower), and it takes more memory on the 16-byte key sets (the B/key columns). The set has not been measured on the line_pool.

The same lookup at two speeds

While this release was prepared, one lookup routine on one tree was found to run at two speeds, the slower about half the faster, depending only on the register allocation of the loop that called it (issue #20 has the disassembly and the experiments; established on an Apple M5). find used to be an out-of-line function: it saves the caller's callee-saved registers in pairs on entry and reloads them on exit. When the compiler happened to keep a value that depends on the previous lookup's result (a running sum, say) in the same pair as the map's address, the next lookup could not start until that value was known, and consecutive lookups stopped overlapping in the out-of-order window. An earlier version of this README took the slow state for a property of line_pool on uniform random integers. It was not: see the line_pool rows under Point lookups.

What was done about it: find(key, out) and contains(key) are now inlined into their caller (ARTPP_LOOKUP_INLINE; define it empty to opt out), which removes the per-lookup save and restore, and the benchmark's timed loops no longer hold a result in a register across a call. What remains: lower_bound and the iterators are out-of-line functions like any other, so a loop that accumulates their results can still land in the slow state by register allocation. If such a loop is hot, measure it, and keep the accumulation out of the loop's registers (fold it into memory inside a small non-inlined function, as bench/engine.hpp does).

Compared with other radix trees

libart

libart is a C library. art_insert, art_search and art_delete take a key as const unsigned char* with a length and a value as void*; iteration is by callback (art_iter, art_iter_prefix), and art_minimum / art_maximum return the first and the last leaf. The benchmarks vendor it unmodified (external/libart). What artpp::map adds by being a C++ container:

  • The std::map interface: find, contains, at, operator[], insert_or_assign, emplace / try_emplace, erase by key and by iterator, size, swap, == (API reference).
  • Typed keys through key_codec: strings, string views, byte vectors and every integral type are built in, and integers iterate in numeric order, negatives included. Other types get a codec specialization, or the optional psio adapter (doubles, reflected structs). libart takes bytes; encoding them is the caller's work.
  • Ordered iteration in both directions through iterators (begin / end, rbegin / rend, range-for). libart iterates forward, through a callback.
  • lower_bound / upper_bound / equal_range. libart has no call that positions at the first key not less than a given one.
  • Value semantics. A mapped value is a C++ object that the container constructs in place and destroys, including non-trivial types such as std::string and move-only types. libart stores a void*; what it points to is the caller's to allocate and free.
  • Allocator awareness. Every node and every value goes through a standard allocator, PMR included; the bundled line_pool adds 4-byte handles and file-backed images that reopen without a rebuild. libart calls calloc and free.
  • artpp::set, the keys-only container.
  • Structural modes (buckets, adaptive, dense_tiers, wide_stems) with the same semantics (Modes).
  • Exception-safety guarantees, stated per operation and tested by fault injection (Limits and guarantees).
  • Stack use that does not grow with the depth of the tree (same section). libart's insert, delete, iteration and destroy are recursive, one call per level.

What libart has that artpp does not:

  • It is C. It can be called from C and from any language with a C foreign function interface. artpp needs a C++20 compiler, GCC or Clang.
  • It is small: two files, art.c and art.h, about 800 lines together.
  • art_iter_prefix visits every key with a given prefix in one call. artpp has no dedicated prefix call. The equivalent for byte-string keys is lower_bound(prefix) followed by iteration for as long as the key starts with the prefix.

art_insert_no_replace corresponds to emplace, and art_minimum / art_maximum to begin() and --end().

Measured against libart (Performance, both allocators): Point lookups against libart: on the Apple M5 Max 1.14–1.97× faster on all four workloads with both allocators; on the x86-64 server 1.06–1.11× on dictionary words, 0.96–1.05× on clustered strings, 1.44–3.49× on sequential integers and 0.68–0.78× on uniform random integers, which is slower. Inserts are 0.70–1.14× (M5) and 0.51–0.92× (x86) libart's speed on the two string workloads and 0.91–1.91× and 1.22–1.81× on the two integer workloads; below 1 is slower, and dictionary words are slower on both machines. On 32-byte keys at 10M, lookups are 1.36× libart's speed on the M5 and 0.75–0.77× on the x86-64 server.

unodb

unodb is a C++20 ART library and the other general-purpose C++ ART measured here. The statements below are from its README and sources at commit 93f6977, the checkout the M5 benchmark was built from.

Where artpp is more general:

  • Keys. unodb takes integral keys (its README: "only std::uint64_t is tested at this time") and variable-length key_view keys, with the restriction "that no full length key may be a prefix of another key". Text keys therefore go through its key_encoder, which truncates them to a maximum length and pads them, and decoding such a key back to text is not supported. artpp stores any byte string of up to 65535 bytes as it is, a key may be a prefix of another, and iteration returns the key.
  • Values. unodb stores value_view byte spans, which it copies, or a trivially copyable type (a static_assert in art_internal_impl.hpp). artpp stores any move-constructible type, including non-trivial and move-only ones, and destroys it.
  • Interface. unodb's documented API is get, insert, remove, clear, empty and a family of scan callbacks. artpp has the std::map interface: iterators, lower_bound / upper_bound, and an allocator parameter.
  • Dependencies. unodb requires Boost (Boost.Container) and, on Intel processors, SSE4.1 at least. artpp is header-only with no dependencies and needs no more than SSE2 on x86-64.

Where unodb offers what artpp does not:

  • Concurrency. olc_db is a concurrent tree (optimistic lock coupling with quiescent-state-based reclamation) and mutex_db a mutex-guarded one. artpp has the thread safety of a standard container and no concurrent variant.
  • MSVC is a supported compiler. artpp supports GCC and Clang only.

Measured against unodb (32-byte keys): on random 32-byte keys, 10M of them, lookups are 4.76–4.77× (M5) and 4.24–4.36× (x86) faster, inserts 2.94–4.01× (M5) and 2.16–3.49× (x86), ordered scans 11.71–12.38× (M5) and 5.18–5.62× (x86) and lower_bound 4.58–4.90× (M5) and 1.94–2.04× (x86); the ranges cover both allocators. unodb was run single-threaded as unodb::db; its concurrent tree was not measured.

art_map

art_map is, in the words of unodb's README, "a C++14 template library providing std::-like interface over the ART data structure". Its key must fit in one integer of at most 16 bytes: bench/bench_buffer.cpp records that a 32-byte key fails to compile (static_assert, "Unsupported key type"). So art_map cannot hold strings or other variable-length keys, nor fixed-width keys longer than 16 bytes, and artpp can. That is a statement about generality only. art_map was not measured for this release, and nothing here says that artpp is faster than art_map on the keys art_map supports.

Benchmark suite

-DARTPP_BENCHMARKS=ON builds artpp_bench: one templated engine (bench/engine.hpp) drives every contestant through identical code — the same key vectors, op sequences, and checksum accounting — so the comparison carries no per-library benchmark deviations. Contestants are thin adapters (bench/contestants.hpp):

  • artpp::map three ways: on the line_pool (the artpp::map row), on the line_pool with mode::buckets, and on std::allocator
  • upstream libart, vendored under external/libart (bytes-only: integer workloads use the same big-endian bytes artpp's integral codec produces)
  • absl::btree_map (installed abseil or fetched; heterogeneous lookup enabled)
  • std::map (reference row)

Workloads: dict (system word list), clustered (synthetic shared-prefix strings), uniform and sequential (typed uint64_t). Ops: insert, point hit, point miss, lower_bound, full ordered scan, erase (libart has no lower_bound, so it has no row for it). Results print as a table and land in results.csv (one row per contestant × workload × op) for charting. The same build has artpp_bench_buffer (the 32-byte keys; unodb on the same keys is bench/bench_buffer_unodb.cpp, built by hand against a unodb checkout as its header comment describes) and artpp_ordered_bench (the set table). artpp_bench_filebacked (the file-backed comparison) is built when the Boost headers are found, with the suite or alone with -DARTPP_BENCH_FILEBACKED=ON.

cmake -B build -DARTPP_BENCHMARKS=ON && cmake --build build -j
./build/bin/artpp_bench            # [N] [scan_reps] [csv_path] [contestants]
./build/bin/artpp_bench_buffer 10000000
./build/bin/artpp_ordered_bench
./build/bin/artpp_bench_filebacked 1000000 5 out.csv /path/on/a/real/disk

The published numbers are several such runs per machine, summarized by python3 docs/bench/2026-11-28/summary.py (Performance).

tools/perf_gate.py is the regression gate: it builds this same benchmark against the working tree and against a baseline commit's headers, runs the two interleaved, and reports paired ratios per operation, workload and allocator, with libart and absl::btree_map as the control (see CONTRIBUTING.md). It is not run in CI; run it alone on a quiet machine.

Testing

ctest runs the functional suite:

binary scope
artpp_smoke API basics in the default, dense_tiers, buckets and adaptive modes, allocator routing (counting, PMR, wide-handle, pool), typed keys, std::map API-conformance battery, randomized cross-checks
artpp_conformance STL-grade contracts: key-length limit, move-construction and move-assignment branches incl. pool image adoption and structural clone, exactly-once construction, move-only values, compile-time constraints, string_view key parameters, erase(iterator), structural equality incl. shape-divergent trees, iterator edge cases, degenerate shapes, mixed-op differential fuzz vs std::map (default, buckets, adaptive, dense_tiers, wide_stems)
artpp_reverse_iter Bidirectional iteration fuzz vs std::map and std::set: churn, full walks both directions, --end(), random lower_bound + backward steps, ++/-- ping-pong; the reverse iterators of map and set dereferenced directly (string_view keys, inline values), base(), std algorithms over the reverse range
artpp_exception_safety Exception safety under systematic fault injection, in the default, buckets, adaptive, dense_tiers and wide_stems modes (and combinations) and for artpp::set: the allocator failing at every allocation point, and value constructors throwing at every construction, of random operation sequences (insert, assign, emplace, operator[], erase, clear, cross-allocator move) and of targeted scenarios (leaf and prefix splits, router widening, bucket overflow, bucket repacking on erase, leaf-to-bucket collapse, structural clone); contents checked against a std::map oracle after every failure (validity and leaks only for the bulk-insert and clone sweeps), with leak and double-destroy counters. ARTPP_EH_SEEDS / ARTPP_EH_OPS lengthen the run
artpp_regression Deterministic guards for fixed bugs: fuzzer-found shapes, and the pre-release audit's (erase cascades past the path window, no restructuring on assignment to a present key, over-aligned values, deep trees on a small stack in each of the five base modes, blocks the handle cannot address, bool keys, values without a default constructor)
artpp_wide_stems setlist_u16 (wide-stem) cross-checks and depth/latency demonstration
artpp_psio_codec (with ARTPP_WITH_PSIO; not built in CI) double and reflected-struct keys vs std::map ordering oracles; optional keys (nullopt first)
artpp_persistence file-backed line_pool survives close + reopen: 40k-key round-trip through a full teardown, then further inserts verified through a second reopen (a final erase is checkpointed but not re-read); restores carving state + root with no relocation
artpp_pool_safety the file-backed line_pool contract: never-checkpointed stores, map destruction after a checkpoint, repeated attach / mutate / checkpoint / reopen cycles; both sync levels recording the same image (the reporting of a write error by sync_level::flush is not tested); refusal of truncated, foreign, mismatched and field-corrupted stores without modifying them, of stores mutated after their last checkpoint (also by a writer that died), of a second opener, and of another map instantiation; page-size arithmetic and stores laid out for 64 KB and 1 MB pages; exhaustion at the capacity and at the 2^28-unit handle limits, size overflow, errno reporting, close()
artpp_fuzz_map differential fuzzer vs std::map — every op mirrored on both, full forward/reverse/bound/size agreement; standalone seeded RNG runner (also replays corpus files)
artpp_fuzz_set differential fuzzer vs std::set, covering key suffixes packed in the handle; same seeded runner
artpp_set_smoke artpp::set basics: the facade over the map with no mapped value
artpp_set_conformance STL contracts for artpp::set, and a set attached to a file-backed line_pool

Fuzzing

artpp_fuzz_map is dual-mode. As the ctest binary above it is a deterministic, seeded random runner over std::map as the oracle. Built with -DARTPP_FUZZER=ON (needs a libFuzzer-capable clang — e.g. Homebrew llvm; the build probes for the runtime and skips otherwise) it is a coverage-guided libFuzzer target under ASan+UBSan:

cmake -B build -DARTPP_FUZZER=ON && cmake --build build --target artpp_fuzzer
./build/bin/artpp_fuzzer -max_total_time=60        # or pass a corpus dir
./build/bin/artpp_fuzz_map <corpus-or-crash-file>  # replay a reproducer in the default toolchain

The first input byte selects the config so one corpus exercises every mode (flat / dense_tiers / +ladder_c8 / buckets / adaptive / wide_stems), the line_pool allocator, and a std::string value (external leaves). Keys are drawn from a small alphabet (or, per input, the full byte range) and a recently-used key pool (extend / truncate / mutate a prior key) to manufacture the shared prefixes and wide fan-out that drive the split / widen-ladder / bucket-burst / de-widen transitions; any divergence aborts with the input bytes for replay.

Status and versioning

The current version is 0.1.0 (2026-11-28), the first release. Before 1.0 the API may change between minor versions; changes are recorded in CHANGELOG.md. The on-disk format of a file-backed line_pool is specific to the library version: a store is only guaranteed to open with the version that wrote it (see What is not guaranteed). 0.1.0 writes store format version 2 (line_pool::VERSION); a store of any other format version is refused with artpp::store_incompatible.

Contributing

See CONTRIBUTING.md. Bugs and feature requests go to the issue tracker.

License

MIT; see LICENSE.

The benchmark suite (not the library) vendors upstream libart under the BSD 3-Clause license; see external/libart/LICENSE.

About

artpp::map — header-only adaptive radix tree map for C++23. Headerless dispatch, O(key-length) ops, allocator-aware, faster point lookups than libart and absl::btree.

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages