Removed FnvHash and transformed the rest to FxHashmap (#39233)

This should be the final PR for the Hash Function series that is
trivial.

Of note: I decided to transform `HashMapTracedValues<Atom,..>` to use
FxBuildHasher. This is likely not going to improve performance as Atom's
already have a unique u32 that is used as the Hash but it safes a few
bytes for the RandomState that is normally in the HashMap.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>

Testing: Hash function changes should not change functionality, we
slightly decrease the size and unit tests still work.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This commit is contained in:
Narfinger 2025-09-10 15:34:54 +02:00 committed by GitHub
parent 726b456120
commit 84465e7768
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
55 changed files with 211 additions and 202 deletions

View file

@ -22,7 +22,6 @@ base = { workspace = true }
bitflags = { workspace = true }
compositing_traits = { workspace = true }
euclid = { workspace = true }
fnv = { workspace = true }
fonts_traits = { workspace = true }
fontsan = { git = "https://github.com/servo/fontsan" }
# FIXME (#34517): macOS only needs this when building libservo without `--features media-gstreamer`
@ -46,6 +45,7 @@ servo_config = { path = "../config" }
servo_url = { path = "../url" }
skrifa = { workspace = true }
smallvec = { workspace = true }
rustc-hash = { workspace = true }
stylo = { workspace = true }
stylo_atoms = { workspace = true }
tracing = { workspace = true, optional = true }

View file

@ -4,7 +4,7 @@
use std::collections::{HashMap, HashSet};
use std::default::Default;
use std::hash::{BuildHasherDefault, Hash, Hasher};
use std::hash::{Hash, Hasher};
use std::ops::Deref;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
@ -12,7 +12,6 @@ use std::sync::atomic::{AtomicBool, Ordering};
use app_units::Au;
use base::id::WebViewId;
use compositing_traits::CrossProcessCompositorApi;
use fnv::FnvHasher;
use fonts_traits::{
CSSFontFaceDescriptors, FontDescriptor, FontIdentifier, FontTemplate, FontTemplateRef,
FontTemplateRefMethods, StylesheetWebFontLoadFinishedCallback,
@ -22,6 +21,7 @@ use malloc_size_of_derive::MallocSizeOf;
use net_traits::request::{Destination, Referrer, RequestBuilder};
use net_traits::{CoreResourceThread, FetchResponseMsg, ResourceThreads, fetch_async};
use parking_lot::{Mutex, RwLock};
use rustc_hash::FxHashSet;
use servo_arc::Arc as ServoArc;
use servo_config::pref;
use servo_url::ServoUrl;
@ -78,8 +78,7 @@ pub struct FontContext {
/// A caching map between the specification of a font in CSS style and
/// resolved [`FontGroup`] which contains information about all fonts that
/// can be selected with that style.
resolved_font_groups:
RwLock<HashMap<FontGroupCacheKey, FontGroupRef, BuildHasherDefault<FnvHasher>>>,
resolved_font_groups: RwLock<HashMap<FontGroupCacheKey, FontGroupRef>>,
web_fonts: CrossThreadFontStore,
@ -612,7 +611,7 @@ impl FontContextWebFontMethods for Arc<FontContext> {
self.have_removed_web_fonts.store(false, Ordering::Relaxed);
let mut removed_keys: HashSet<FontKey> = HashSet::new();
let mut removed_keys: FxHashSet<FontKey> = FxHashSet::default();
webrender_font_keys.retain(|identifier, font_key| {
if unused_identifiers.contains(identifier) {
removed_keys.insert(*font_key);