Skip to content

Commit f80ee5d

Browse files
committed
perf(sdk): use ahash for ValueMap HashMaps in metrics hot path
Replace the default SipHash-1-3 hasher with ahash (AES-NI backed) 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. ahash leverages hardware AES instructions for significantly faster hashing of Vec<KeyValue> keys. Refs: #3371 Co-Authored-By: Bryant Biggs <bryantbiggs@gmail.com>
1 parent dba1820 commit f80ee5d

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

opentelemetry-sdk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ rust-version = "1.75.0"
1111
autobenches = false
1212

1313
[dependencies]
14+
ahash = "0.8"
1415
opentelemetry = { workspace = true }
1516
opentelemetry-http = { workspace = true, optional = true }
1617
futures-channel = { workspace = true }

opentelemetry-sdk/src/metrics/internal/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ mod last_value;
55
mod precomputed_sum;
66
mod sum;
77

8+
use ahash::AHashMap as HashMap;
89
use core::fmt;
910
#[cfg(not(target_has_atomic = "64"))]
1011
use portable_atomic::{AtomicI64, AtomicU64};
1112
use std::cmp::min;
12-
use std::collections::{HashMap, HashSet};
13+
use std::collections::HashSet;
1314
use std::mem::swap;
1415
use std::ops::{Add, AddAssign, DerefMut, Sub};
1516
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};

0 commit comments

Comments
 (0)