Moves to FxHashMap for Allocator, BHM, Canvas, Media, Servo, WebGL and WebGPU (#39202)

This moves more of HashMap/FnvHashMap to FxHashmap. Again we only
changed instances that do not look security related and have small keys.

Additionally, allocator used the fnv feature which did not seem to be
used.

Testing: Unit Tests and WPT should cover this and functionality change
is highly unlikely.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This commit is contained in:
Narfinger 2025-09-08 18:06:03 +02:00 committed by GitHub
parent 228b240635
commit d2c78db981
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 53 additions and 46 deletions

View file

@ -11,12 +11,12 @@ rust-version.workspace = true
path = "lib.rs"
[features]
allocation-tracking = ["backtrace", "fnv"]
allocation-tracking = ["backtrace", "dep:rustc-hash"]
use-system-allocator = ["libc"]
[dependencies]
backtrace = { workspace = true, optional = true }
fnv = { workspace = true, optional = true }
rustc-hash = { workspace = true, optional = true }
[target.'cfg(not(any(windows, target_env = "ohos")))'.dependencies]
libc = { workspace = true, optional = true }

View file

@ -12,7 +12,7 @@ use std::collections::hash_map::Entry;
use std::os::raw::c_void;
use std::sync::Mutex;
use fnv::{FnvBuildHasher, FnvHashMap};
use rustc_hash::{FxBuildHasher, FxHashMap};
/// The maximum number of allocations that we'll keep track of. Once the limit
/// is reached, we'll evict the first allocation that is smaller than the new addition.
@ -54,8 +54,8 @@ impl AllocSite {
unsafe impl Send for AllocSite {}
/// A map of pointers to allocation callsite metadata.
static ALLOCATION_SITES: Mutex<FnvHashMap<usize, AllocSite>> =
const { Mutex::new(FnvHashMap::with_hasher(FnvBuildHasher::new())) };
static ALLOCATION_SITES: Mutex<FxHashMap<usize, AllocSite>> =
const { Mutex::new(FxHashMap::default()) };
#[derive(Default)]
pub struct AccountingAlloc<A = System> {