# Billion-query-per-second lookup tables in C++

DevFeed: [Billion-query-per-second lookup tables in C++](<https://devfeed.tech/articles/billion-query-per-second-lookup-tables-in-c-101123.md>)

Original publisher: [Read original article](<https://lemire.me/blog/2026/10/26/billion-query-per-second-lookup-tables-in-c/>)

Author: Daniel Lemire

Published: 2026-10-26T18:23:08Z

Content type: article

Language: en

Sources: [Daniel Lemire](<https://devfeed.tech/sources/daniel-lemire.md>)

Topics: [stl](<https://devfeed.tech/topics/stl.md>), [clang](<https://devfeed.tech/topics/clang.md>), [Parser](<https://devfeed.tech/topics/parser.md>)

Tags: [abseil](<https://devfeed.tech/tags/abseil.md>), [algorithm](<https://devfeed.tech/tags/algorithm.md>), [apple](<https://devfeed.tech/tags/apple.md>), [arm](<https://devfeed.tech/tags/arm.md>), [benchmark](<https://devfeed.tech/tags/benchmark.md>), [benchmarks](<https://devfeed.tech/tags/benchmarks.md>), [branch](<https://devfeed.tech/tags/branch.md>), [buffer](<https://devfeed.tech/tags/buffer.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [c-plus-plus-23](<https://devfeed.tech/tags/c-plus-plus-23.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [lookup](<https://devfeed.tech/tags/lookup.md>), [mapping](<https://devfeed.tech/tags/mapping.md>), [tables](<https://devfeed.tech/tags/tables.md>)

## AI overview

For fixed string keys, the described C++23 library builds a perfect hash at compile time, avoiding runtime collision handling. It chooses association values greedily for selected key characters; lookup computes a slot and verifies the stored key. The implementation also uses a 16-byte vector comparison, with a slower path when a wide load could cross a memory-page boundary. On an Apple M3 Max, the article reports about 1.3 ns per lookup for 20 HTTP headers, versus 7.7 ns for gperf, 10.9 ns for Abseil flat_hash_map, and 16.6 ns for std::unordered_map. Across other tested key sets it reports 1.2-2 ns per lookup; results are specific to the stated benchmarks and hardware.

## Source excerpt

A lot of software spends its time mapping strings to values. A web server must identify the HTTP method (GET, POST, ...). It must recognize header names. A URL parser must recognize the protocol (http, https, ftp, ...). A compiler must recognize keywords. In C++, the default approach is to put the strings in a ... Continue reading Billion-query-per-second lookup tables in C++