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

@ -15,6 +15,7 @@ path = "lib.rs"
arrayvec = { workspace = true, features = ["serde"] }
base = { workspace = true }
compositing_traits = { workspace = true }
rustc-hash = { workspace = true }
euclid = { workspace = true }
ipc-channel = { workspace = true }
log = { workspace = true }

View file

@ -2,7 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::collections::HashMap;
use std::ptr::NonNull;
use std::slice;
use std::sync::{Arc, Mutex};
@ -17,6 +16,7 @@ use euclid::default::Size2D;
use ipc_channel::ipc::IpcSender;
use log::{error, warn};
use pixels::{IpcSnapshot, Snapshot, SnapshotAlphaMode, SnapshotPixelFormat};
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use webgpu_traits::{
ContextConfiguration, Error, PRESENTATION_BUFFER_COUNT, WebGPUContextId, WebGPUMsg,
@ -35,7 +35,7 @@ use crate::wgt;
const DEFAULT_IMAGE_FORMAT: ImageFormat = ImageFormat::RGBA8;
pub type WGPUImageMap = Arc<Mutex<HashMap<WebGPUContextId, ContextData>>>;
pub type WGPUImageMap = Arc<Mutex<FxHashMap<WebGPUContextId, ContextData>>>;
/// Presentation id encodes current configuration and current image
/// so that async presentation does not update context with older data
@ -80,7 +80,7 @@ impl Drop for GPUPresentationBuffer {
#[derive(Default)]
pub struct WGPUExternalImages {
pub images: WGPUImageMap,
pub locked_ids: HashMap<WebGPUContextId, Vec<u8>>,
pub locked_ids: FxHashMap<WebGPUContextId, Vec<u8>>,
}
impl WebrenderExternalImageApi for WGPUExternalImages {

View file

@ -5,7 +5,6 @@
//! Data and main loop of WebGPU thread.
use std::borrow::Cow;
use std::collections::HashMap;
use std::slice;
use std::sync::{Arc, Mutex};
@ -15,6 +14,7 @@ use compositing_traits::{
};
use ipc_channel::ipc::{IpcReceiver, IpcSender, IpcSharedMemory};
use log::{info, warn};
use rustc_hash::FxHashMap;
use servo_config::pref;
use webgpu_traits::{
Adapter, ComputePassId, DeviceLostReason, Error, ErrorScope, Mapping, Pipeline, PopError,
@ -98,21 +98,21 @@ pub(crate) struct WGPU {
sender: IpcSender<WebGPURequest>,
pub(crate) script_sender: IpcSender<WebGPUMsg>,
pub(crate) global: Arc<wgc::global::Global>,
devices: Arc<Mutex<HashMap<DeviceId, DeviceScope>>>,
devices: Arc<Mutex<FxHashMap<DeviceId, DeviceScope>>>,
// TODO: Remove this (https://github.com/gfx-rs/wgpu/issues/867)
/// This stores first error on command encoder,
/// because wgpu does not invalidate command encoder object
/// (this is also reused for invalidation of command buffers)
error_command_encoders: HashMap<id::CommandEncoderId, String>,
error_command_encoders: FxHashMap<id::CommandEncoderId, String>,
pub(crate) compositor_api: CrossProcessCompositorApi,
pub(crate) external_images: Arc<Mutex<WebrenderExternalImageRegistry>>,
pub(crate) wgpu_image_map: WGPUImageMap,
/// Provides access to poller thread
pub(crate) poller: Poller,
/// Store compute passes
compute_passes: HashMap<ComputePassId, Pass<ComputePass>>,
compute_passes: FxHashMap<ComputePassId, Pass<ComputePass>>,
/// Store render passes
render_passes: HashMap<RenderPassId, Pass<RenderPass>>,
render_passes: FxHashMap<RenderPassId, Pass<RenderPass>>,
}
impl WGPU {
@ -147,13 +147,13 @@ impl WGPU {
sender,
script_sender,
global,
devices: Arc::new(Mutex::new(HashMap::new())),
error_command_encoders: HashMap::new(),
devices: Arc::new(Mutex::new(FxHashMap::default())),
error_command_encoders: FxHashMap::default(),
compositor_api,
external_images,
wgpu_image_map,
compute_passes: HashMap::new(),
render_passes: HashMap::new(),
compute_passes: FxHashMap::default(),
render_passes: FxHashMap::default(),
}
}