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

@ -16,13 +16,13 @@ no-wgl = ["surfman/sm-angle-default"]
[dependencies]
base = { workspace = true }
rustc-hash = { workspace = true }
bincode = { workspace = true }
bitflags = { workspace = true }
crossbeam-channel = { workspace = true }
dpi = { version = "0.1" }
embedder_traits = { workspace = true }
euclid = { workspace = true }
fnv = { workspace = true }
gleam = { workspace = true }
glow = { workspace = true }
image = { workspace = true }

View file

@ -12,8 +12,8 @@ use base::print_tree::PrintTree;
use bitflags::bitflags;
use embedder_traits::ViewportDetails;
use euclid::SideOffsets2D;
use fnv::FnvHashMap;
use malloc_size_of_derive::MallocSizeOf;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use servo_geometry::FastLayoutTransform;
use style::values::specified::Overflow;
@ -561,7 +561,7 @@ impl ScrollTree {
/// for nodes that actually exist in this tree.
pub fn set_all_scroll_offsets(
&mut self,
offsets: &FnvHashMap<ExternalScrollId, LayoutVector2D>,
offsets: &FxHashMap<ExternalScrollId, LayoutVector2D>,
) {
for node in self.nodes.iter_mut() {
if let SpatialTreeNodeInfo::Scroll(ref mut scroll_info) = node.info {
@ -587,7 +587,7 @@ impl ScrollTree {
/// Collect all of the scroll offsets of the scrolling nodes of this tree into a
/// [`HashMap`] which can be applied to another tree.
pub fn scroll_offsets(&self) -> FnvHashMap<ExternalScrollId, LayoutVector2D> {
pub fn scroll_offsets(&self) -> FxHashMap<ExternalScrollId, LayoutVector2D> {
HashMap::from_iter(self.nodes.iter().filter_map(|node| match node.info {
SpatialTreeNodeInfo::Scroll(ref scroll_info) => {
Some((scroll_info.external_id, scroll_info.offset))

View file

@ -23,7 +23,6 @@ devtools_traits = { workspace = true }
embedder_traits = { workspace = true }
euclid = { workspace = true }
fonts_traits = { workspace = true }
fnv = { workspace = true }
rustc-hash = { workspace = true }
http = { workspace = true }
hyper_serde = { workspace = true }

View file

@ -21,7 +21,6 @@ use embedder_traits::{
ViewportDetails, WebDriverMessageId,
};
use euclid::default::Size2D as UntypedSize2D;
use fnv::FnvHashMap;
use fonts_traits::SystemFontServiceProxySender;
use http::{HeaderMap, Method};
use ipc_channel::ipc::IpcSender;
@ -32,6 +31,7 @@ use net_traits::storage_thread::StorageType;
use net_traits::{ReferrerPolicy, ResourceThreads};
use profile_traits::mem::MemoryReportResult;
use profile_traits::{mem, time as profile_time};
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use servo_url::{ImmutableOrigin, ServoUrl};
use strum_macros::IntoStaticStr;
@ -492,7 +492,7 @@ pub enum ScriptToConstellationMessage {
/* The ids of ports transferred successfully */
Vec<MessagePortId>,
/* The ids, and buffers, of ports whose transfer failed */
FnvHashMap<MessagePortId, PortTransferInfo>,
FxHashMap<MessagePortId, PortTransferInfo>,
),
/// A new message-port was created or transferred, with corresponding control-sender.
NewMessagePort(MessagePortRouterId, MessagePortId),

View file

@ -22,11 +22,11 @@ use embedder_traits::{
CompositorHitTestResult, InputEvent, JavaScriptEvaluationId, MediaSessionActionType, Theme,
TraversalId, ViewportDetails, WebDriverCommandMsg, WebDriverCommandResponse,
};
use fnv::FnvHashMap;
pub use from_script_message::*;
use ipc_channel::ipc::IpcSender;
use malloc_size_of_derive::MallocSizeOf;
use profile_traits::mem::MemoryReportResult;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use servo_config::prefs::PrefValue;
use servo_url::{ImmutableOrigin, ServoUrl};
@ -42,7 +42,7 @@ pub enum EmbedderToConstellationMessage {
/// Exit the constellation.
Exit,
/// Query the constellation to see if the current compositor output is stable
IsReadyToSaveImage(FnvHashMap<PipelineId, Epoch>),
IsReadyToSaveImage(FxHashMap<PipelineId, Epoch>),
/// Whether to allow script to navigate.
AllowNavigationResponse(PipelineId, bool),
/// Request to load a page.
@ -95,7 +95,7 @@ pub enum EmbedderToConstellationMessage {
SetWebViewThrottled(WebViewId, bool),
/// The Servo renderer scrolled and is updating the scroll states of the nodes in the
/// given pipeline via the constellation.
SetScrollStates(PipelineId, FnvHashMap<ExternalScrollId, LayoutVector2D>),
SetScrollStates(PipelineId, FxHashMap<ExternalScrollId, LayoutVector2D>),
/// Notify the constellation that a particular paint metric event has happened for the given pipeline.
PaintMetric(PipelineId, PaintMetricEvent),
/// Evaluate a JavaScript string in the context of a `WebView`. When execution is complete or an
@ -181,7 +181,7 @@ pub struct PortTransferInfo {
#[allow(clippy::large_enum_variant)]
pub enum MessagePortMsg {
/// Complete the transfer for a batch of ports.
CompleteTransfer(FnvHashMap<MessagePortId, PortTransferInfo>),
CompleteTransfer(FxHashMap<MessagePortId, PortTransferInfo>),
/// Complete the transfer of a single port,
/// whose transfer was pending because it had been requested
/// while a previous failed transfer was being rolled-back.

View file

@ -25,6 +25,7 @@ http = { workspace = true }
hyper_serde = { workspace = true }
ipc-channel = { workspace = true }
keyboard-types = { workspace = true }
rustc-hash = { workspace = true }
log = { workspace = true }
malloc_size_of = { workspace = true }
malloc_size_of_derive = { workspace = true }

View file

@ -15,6 +15,7 @@ use hyper_serde::Serde;
use ipc_channel::ipc::IpcSender;
use keyboard_types::{CompositionEvent, KeyboardEvent};
use pixels::RasterImage;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use servo_geometry::DeviceIndependentIntRect;
use servo_url::ServoUrl;
@ -294,7 +295,7 @@ pub enum WebDriverLoadStatus {
/// to a WebDriver server with information about application state.
#[derive(Clone, Default)]
pub struct WebDriverSenders {
pub load_status_senders: HashMap<WebViewId, GenericSender<WebDriverLoadStatus>>,
pub load_status_senders: FxHashMap<WebViewId, GenericSender<WebDriverLoadStatus>>,
pub script_evaluation_interrupt_sender: Option<IpcSender<WebDriverJSResult>>,
pub pending_traversals: HashMap<TraversalId, GenericSender<WebDriverLoadStatus>>,
}

View file

@ -20,7 +20,6 @@ compositing_traits = { workspace = true }
constellation_traits = { workspace = true }
embedder_traits = { workspace = true }
euclid = { workspace = true }
fnv = { workspace = true }
fonts = { path = "../../fonts" }
fonts_traits = { workspace = true }
html5ever = { workspace = true }

View file

@ -28,7 +28,6 @@ use constellation_traits::LoadData;
use embedder_traits::{Cursor, Theme, UntrustedNodeAddress, ViewportDetails};
use euclid::Point2D;
use euclid::default::{Point2D as UntypedPoint2D, Rect};
use fnv::FnvHashMap;
use fonts::{FontContext, SystemFontServiceProxy};
pub use layout_damage::LayoutDamage;
use libc::c_void;
@ -288,7 +287,7 @@ pub trait Layout {
/// Set the scroll states of this layout after a compositor scroll.
fn set_scroll_offsets_from_renderer(
&mut self,
scroll_states: &FnvHashMap<ExternalScrollId, LayoutVector2D>,
scroll_states: &FxHashMap<ExternalScrollId, LayoutVector2D>,
);
/// Get the scroll offset of the given scroll node with id of [`ExternalScrollId`] or `None` if it does
@ -425,7 +424,7 @@ pub struct IFrameSize {
pub viewport_details: ViewportDetails,
}
pub type IFrameSizes = FnvHashMap<BrowsingContextId, IFrameSize>;
pub type IFrameSizes = FxHashMap<BrowsingContextId, IFrameSize>;
bitflags! {
/// Conditions which cause a [`Document`] to need to be restyled during reflow, which

View file

@ -22,6 +22,7 @@ crossbeam-channel = { workspace = true }
data-url = { workspace = true }
embedder_traits = { workspace = true }
headers = { workspace = true }
rustc-hash = { workspace = true }
http = { workspace = true }
hyper-util = { workspace = true }
hyper_serde = { workspace = true }

View file

@ -4,7 +4,6 @@
#![deny(unsafe_code)]
use std::collections::HashMap;
use std::fmt::Display;
use std::sync::{LazyLock, OnceLock};
use std::thread::{self, JoinHandle};
@ -26,6 +25,7 @@ use malloc_size_of::malloc_size_of_is_0;
use malloc_size_of_derive::MallocSizeOf;
use mime::Mime;
use request::RequestId;
use rustc_hash::FxHashMap;
use rustls_pki_types::CertificateDer;
use serde::{Deserialize, Serialize};
use servo_rand::RngCore;
@ -604,7 +604,7 @@ pub type BoxedFetchCallback = Box<dyn FnMut(FetchResponseMsg) + Send + 'static>;
struct FetchThread {
/// A list of active fetches. A fetch is no longer active once the
/// [`FetchResponseMsg::ProcessResponseEOF`] is received.
active_fetches: HashMap<RequestId, BoxedFetchCallback>,
active_fetches: FxHashMap<RequestId, BoxedFetchCallback>,
/// A crossbeam receiver attached to the router proxy which converts incoming fetch
/// updates from IPC messages to crossbeam messages as well as another sender which
/// handles requests from clients wanting to do fetches.
@ -631,7 +631,7 @@ impl FetchThread {
.name("FetchThread".to_owned())
.spawn(move || {
let mut fetch_thread = FetchThread {
active_fetches: HashMap::new(),
active_fetches: FxHashMap::default(),
receiver,
to_fetch_sender,
};

View file

@ -26,7 +26,7 @@ crossbeam-channel = { workspace = true }
devtools_traits = { workspace = true }
embedder_traits = { workspace = true }
euclid = { workspace = true }
fnv = { workspace = true }
rustc-hash = { workspace = true }
ipc-channel = { workspace = true }
keyboard-types = { workspace = true }
malloc_size_of = { workspace = true }

View file

@ -32,7 +32,6 @@ use embedder_traits::{
MediaSessionActionType, ScriptToEmbedderChan, Theme, ViewportDetails, WebDriverScriptCommand,
};
use euclid::{Rect, Scale, Size2D, UnknownUnit};
use fnv::FnvHashMap;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use keyboard_types::Modifiers;
use malloc_size_of_derive::MallocSizeOf;
@ -42,6 +41,7 @@ use net_traits::image_cache::ImageCache;
use net_traits::storage_thread::StorageType;
use pixels::PixelFormat;
use profile_traits::mem;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use servo_config::prefs::PrefValue;
use servo_url::{ImmutableOrigin, ServoUrl};
@ -253,7 +253,7 @@ pub enum ScriptThreadMessage {
SetWebGPUPort(IpcReceiver<WebGPUMsg>),
/// The compositor scrolled and is updating the scroll states of the nodes in the given
/// pipeline via the Constellation.
SetScrollStates(PipelineId, FnvHashMap<ExternalScrollId, LayoutVector2D>),
SetScrollStates(PipelineId, FxHashMap<ExternalScrollId, LayoutVector2D>),
/// Evaluate the given JavaScript and return a result via a corresponding message
/// to the Constellation.
EvaluateJavaScript(PipelineId, JavaScriptEvaluationId, String),