Skip to content

Benchmarks: pass the compile-time maps as template parameters - #43

Merged
lemire merged 1 commit into
mainfrom
lemire/bench-constant-maps
Nov 14, 2026
Merged

lemire merged 1 commit into
mainfrom
lemire/bench-constant-maps

Conversation

@lemire

@lemire lemire commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Problem

bench_workload and run_keyset received our map, the naive function, frozen's map and constexpr-phf's table as function arguments (const PHFMap &phf_map, ...). The compiler then sees them as constants only if it clones those functions for each call site (GCC's IPA-CP). With ten key sets, GCC 16 made .constprop clones for the first seven and not for JavaScript reserved words, Counters and Java FQCNs. Those three ran a generic lookup that loads num_positions_ and positions_[] from memory and loops over them: 73 instructions per JavaScript hit instead of 39. A program calling a global map does not get that code, so the benchmark under-reported our speed on exactly those three sets (on Emerald Rapids, JavaScript hits measured 3.8 ns instead of 1.9 ns, and gperf looked faster).

Change

Pass the compile-time structures as template parameters (template <const auto &phf_map, auto naive_fn, const auto &frozen_map, const auto &kronuz_phf, typename GperfFn>), in bench_protocol and bench_tickers. Each instantiation then names its constant directly, whatever the compiler's cloning heuristics decide. The function bodies are unchanged. The competitors that are compile-time structures (naive, frozen, constexpr-phf) get the same treatment, so the comparison stays fair. gperf was already called through lambdas on static tables. In bench_tickers, the optional frozen and constexpr-phf pointers become static constexpr and their null checks if constexpr.

bench_protocol --verify passes (10 sets) and bench_tickers --verify passes (4 checks), with Apple clang 17. Measurements on Emerald Rapids / GCC 16 to follow in a comment.

bench_workload and run_keyset took our map, the naive function, frozen's map
and constexpr-phf's table as function arguments. The compiler then sees them
as constants only if it clones those functions for each call site. GCC 16
(IPA-CP) stopped doing that after seven of the ten key sets, so JavaScript
reserved words, counters and Java FQCNs ran a generic lookup, loading the
hash positions from memory, instead of the code a program using a global map
gets. Make them template parameters, in bench_protocol and bench_tickers.
@lemire
lemire merged commit 2d698d8 into main Nov 14, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant