Commit 916519b
committed
perf(sdk): add optional rapidhash for ValueMap HashMaps in metrics hot path
Replace the default SipHash-1-3 hasher with rapidhash (wyhash successor) behind
an opt-in `metrics-use-rapidhash` feature flag for the HashMap used in
ValueMap::trackers. SipHash's HashDoS resistance is unnecessary here since
ValueMap is pub(crate) and keys are not attacker-controlled.
rapidhash was selected after benchmarking four hashers (ahash, foldhash,
rapidhash, std SipHash) on actual Vec<KeyValue> keys matching the ValueMap
workload (1600 time series, 2-8 attributes per entry, mixed read/write).
Benchmark results (Apple Silicon, aarch64-apple-darwin):
| Benchmark (4 attrs) | ahash | foldhash | rapidhash | std SipHash |
|--------------------------|---------|----------|-----------|-------------|
| hash_only | 31.5 µs | 30.7 µs | 29.9 µs | 60.0 µs |
| lookup_hit | 81.2 µs | 71.0 µs | 70.1 µs | 104.8 µs |
| lookup_miss | 2.24 µs | 2.46 µs | 2.13 µs | 4.10 µs |
| insert | 207 µs | 198 µs | 196 µs | 235 µs |
| mixed_rw (ValueMap path) | 170 µs | 155 µs | 153 µs | 218 µs |
Key findings:
- rapidhash is 10% faster than ahash on the mixed read/write path that
most closely models ValueMap::measure()
- foldhash (now hashbrown's default hasher) is 8% faster than ahash
- ahash has known unresolved performance regressions on ARM (#194, ~40%
regression on M1 from 0.8.6->0.8.7) and AMD (#190, 73-151% regression
with target-cpu=native)
- ahash has had no throughput-focused optimization work merged in 2024-2025;
three VAES PRs (#144, #186, #187) have been stalled for 2+ years
- foldhash replaced ahash as the default hasher in hashbrown (PR #563)
- rapidhash is the official successor to wyhash, adopted by Chromium and
Microsoft Terminal
The feature is opt-in to avoid adding a mandatory dependency. When
`metrics-use-rapidhash` is not enabled, the standard library HashMap
(SipHash) is used.
Also adds a hasher_comparison benchmark for reproducing these results.
Refs: #33711 parent dba1820 commit 916519b
File tree
3 files changed
+23
-3
lines changed- opentelemetry-sdk
- src/metrics/internal
3 files changed
+23
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
27 | 44 | | |
28 | 45 | | |
29 | 46 | | |
| |||
85 | 102 | | |
86 | 103 | | |
87 | 104 | | |
88 | | - | |
| 105 | + | |
89 | 106 | | |
90 | 107 | | |
91 | 108 | | |
| |||
100 | 117 | | |
101 | 118 | | |
102 | 119 | | |
103 | | - | |
| 120 | + | |
104 | 121 | | |
105 | 122 | | |
106 | 123 | | |
| |||
0 commit comments