Repository navigation
Benchmarks: pass the compile-time maps as template parameters - #43
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
bench_workloadandrun_keysetreceived 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.constpropclones for the first seven and not for JavaScript reserved words, Counters and Java FQCNs. Those three ran a generic lookup that loadsnum_positions_andpositions_[]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>), inbench_protocolandbench_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. Inbench_tickers, the optional frozen and constexpr-phf pointers becomestatic constexprand their null checksif constexpr.bench_protocol --verifypasses (10 sets) andbench_tickers --verifypasses (4 checks), with Apple clang 17. Measurements on Emerald Rapids / GCC 16 to follow in a comment.