Billion-query-per-second lookup tables in C++
Web page · https://lemire.me/blog/2026/10/26/billion-query-per-second-lookup-tables-in-c
First seen by Oriel on .
AI summary
The ConstexprCore perfect-hash library uses compile-time key generation and SIMD string comparison to achieve roughly five-cycle lookups, reaching over one billion lookups per second on an Apple M4.
- The library accepts ordinary C++23 and generates a collision-free lookup map at compile time without requiring an external tool.
- Its greedy association-table algorithm computes slots using key length and selected characters, with power-of-two table sizes enabling bitwise masking.
- SIMD comparison loads 16 bytes, zeroes bytes beyond the key, and uses a slower path near page boundaries to avoid unsafe reads.
- On an Apple M3 Max, lookups took 1.2–2 ns, compared with 3–6 times longer for gperf and 7–13 times longer for std::unordered_map.
- The approach targets fixed string sets such as HTTP methods, headers, URL protocols, compiler keywords, and stock tickers.
#perfect hashing #c++ #simd #performance
Generated by gpt-5.6-sol. Check the original for details.
Metric trends
Last 30 days · Up to 120 recorded samples per source and metric, with reposts kept separate · First and latest retained
Points
Score reported by the source.
- Hacker News: 31, latest observation ; +28 over observed period since
- Lobsters: 24, latest observation ; +23 over observed period since
Comments
Comment count reported by the source.
- Hacker News: 4, latest observation ; +4 over observed period since
- Lobsters: 7, latest observation ; +7 over observed period since
Aliases
| Source | External ID | URL |
|---|---|---|
| Hacker News | 50268325 | https://lemire.me/blog/2026/10/26/billion-query-per-second-lookup-tables-in-c/ Read discussion |
| Hacker News | 50271088 | https://lemire.me/blog/2026/10/26/billion-query-per-second-lookup-tables-in-c/ Read discussion |
| Lobsters | d3ubhd | https://lemire.me/blog/2026/10/26/billion-query-per-second-lookup-tables-in-c/ Read discussion |