mirror of
https://github.com/servo/servo.git
synced 2025-09-23 05:10:09 +01:00
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:
parent
228b240635
commit
d2c78db981
19 changed files with 53 additions and 46 deletions
|
@ -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 }
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -17,6 +17,7 @@ doctest = false
|
|||
background_hang_monitor_api = { workspace = true }
|
||||
backtrace = { workspace = true }
|
||||
base = { workspace = true }
|
||||
rustc-hash = { workspace = true }
|
||||
crossbeam-channel = { workspace = true }
|
||||
ipc-channel = { workspace = true }
|
||||
libc = { workspace = true }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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, VecDeque};
|
||||
use std::collections::VecDeque;
|
||||
use std::thread::{self, Builder, JoinHandle};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
|
@ -14,6 +14,7 @@ use background_hang_monitor_api::{
|
|||
use crossbeam_channel::{Receiver, Sender, after, never, select, unbounded};
|
||||
use ipc_channel::ipc::{IpcReceiver, IpcSender};
|
||||
use ipc_channel::router::ROUTER;
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::sampler::{NativeStack, Sampler};
|
||||
|
||||
|
@ -208,8 +209,8 @@ struct MonitoredComponent {
|
|||
struct Sample(MonitoredComponentId, Instant, NativeStack);
|
||||
|
||||
struct BackgroundHangMonitorWorker {
|
||||
component_names: HashMap<MonitoredComponentId, String>,
|
||||
monitored_components: HashMap<MonitoredComponentId, MonitoredComponent>,
|
||||
component_names: FxHashMap<MonitoredComponentId, String>,
|
||||
monitored_components: FxHashMap<MonitoredComponentId, MonitoredComponent>,
|
||||
constellation_chan: IpcSender<HangMonitorAlert>,
|
||||
port: Receiver<(MonitoredComponentId, MonitoredComponentMsg)>,
|
||||
control_port: Receiver<BackgroundHangMonitorControlMsg>,
|
||||
|
|
|
@ -28,6 +28,7 @@ euclid = { workspace = true }
|
|||
fonts = { path = "../fonts" }
|
||||
ipc-channel = { workspace = true }
|
||||
kurbo = { workspace = true }
|
||||
rustc-hash = { workspace = true }
|
||||
log = { workspace = true }
|
||||
net_traits = { workspace = true }
|
||||
peniko = { workspace = true, optional = true }
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::borrow::ToOwned;
|
||||
use std::collections::HashMap;
|
||||
use std::{f32, thread};
|
||||
|
||||
use base::Epoch;
|
||||
|
@ -16,12 +15,13 @@ use ipc_channel::ipc::{self, IpcSender};
|
|||
use ipc_channel::router::ROUTER;
|
||||
use log::warn;
|
||||
use pixels::Snapshot;
|
||||
use rustc_hash::FxHashMap;
|
||||
use webrender_api::ImageKey;
|
||||
|
||||
use crate::canvas_data::*;
|
||||
|
||||
pub struct CanvasPaintThread {
|
||||
canvases: HashMap<CanvasId, Canvas>,
|
||||
canvases: FxHashMap<CanvasId, Canvas>,
|
||||
next_canvas_id: CanvasId,
|
||||
compositor_api: CrossProcessCompositorApi,
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ pub struct CanvasPaintThread {
|
|||
impl CanvasPaintThread {
|
||||
fn new(compositor_api: CrossProcessCompositorApi) -> CanvasPaintThread {
|
||||
CanvasPaintThread {
|
||||
canvases: HashMap::new(),
|
||||
canvases: FxHashMap::default(),
|
||||
next_canvas_id: CanvasId(0),
|
||||
compositor_api: compositor_api.clone(),
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ path = "lib.rs"
|
|||
[dependencies]
|
||||
compositing_traits = { workspace = true }
|
||||
euclid = { workspace = true }
|
||||
fnv = { workspace = true }
|
||||
rustc-hash = { workspace = true }
|
||||
ipc-channel = { workspace = true }
|
||||
log = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
|
|
|
@ -6,9 +6,9 @@ use std::sync::{Arc, Mutex};
|
|||
use std::thread;
|
||||
|
||||
use compositing_traits::{WebrenderExternalImageRegistry, WebrenderImageHandlerType};
|
||||
use fnv::FnvHashMap;
|
||||
use ipc_channel::ipc::{IpcSender, channel};
|
||||
use log::{trace, warn};
|
||||
use rustc_hash::FxHashMap;
|
||||
use webrender_api::ExternalImageId;
|
||||
|
||||
/// GL player threading API entry point that lives in the
|
||||
|
@ -19,7 +19,7 @@ use crate::{GLPlayerMsg, GLPlayerMsgForward};
|
|||
/// a set of video players with GL render.
|
||||
pub struct GLPlayerThread {
|
||||
/// Map of live players.
|
||||
players: FnvHashMap<u64, IpcSender<GLPlayerMsgForward>>,
|
||||
players: FxHashMap<u64, IpcSender<GLPlayerMsgForward>>,
|
||||
/// List of registered webrender external images.
|
||||
/// We use it to get an unique ID for new players.
|
||||
external_images: Arc<Mutex<WebrenderExternalImageRegistry>>,
|
||||
|
|
|
@ -67,6 +67,7 @@ vello_cpu = ["constellation/vello_cpu"]
|
|||
[dependencies]
|
||||
background_hang_monitor = { path = "../background_hang_monitor" }
|
||||
base = { workspace = true }
|
||||
rustc-hash = { workspace = true }
|
||||
bincode = { workspace = true }
|
||||
bluetooth = { path = "../bluetooth", optional = true }
|
||||
bluetooth_traits = { workspace = true, optional = true }
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
* 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 base::id::WebViewId;
|
||||
use constellation_traits::EmbedderToConstellationMessage;
|
||||
use embedder_traits::{JSValue, JavaScriptEvaluationError, JavaScriptEvaluationId};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::ConstellationProxy;
|
||||
|
||||
|
@ -17,7 +16,7 @@ struct PendingEvaluation {
|
|||
pub(crate) struct JavaScriptEvaluator {
|
||||
current_id: JavaScriptEvaluationId,
|
||||
constellation_proxy: ConstellationProxy,
|
||||
pending_evaluations: HashMap<JavaScriptEvaluationId, PendingEvaluation>,
|
||||
pending_evaluations: FxHashMap<JavaScriptEvaluationId, PendingEvaluation>,
|
||||
}
|
||||
|
||||
impl JavaScriptEvaluator {
|
||||
|
|
|
@ -27,7 +27,6 @@ mod webview_delegate;
|
|||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::cmp::max;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::{Rc, Weak};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
@ -96,6 +95,7 @@ use net_traits::{exit_fetch_thread, start_fetch_thread};
|
|||
use profile::{mem as profile_mem, time as profile_time};
|
||||
use profile_traits::mem::MemoryReportResult;
|
||||
use profile_traits::{mem, time};
|
||||
use rustc_hash::FxHashMap;
|
||||
use script::{JSEngineSetup, ServiceWorkerManager};
|
||||
use servo_config::opts::Opts;
|
||||
pub use servo_config::prefs::PrefValue;
|
||||
|
@ -209,7 +209,7 @@ pub struct Servo {
|
|||
/// as `Weak` references so that the embedding application can control their lifetime.
|
||||
/// When accessed, `Servo` will be reponsible for cleaning up the invalid `Weak`
|
||||
/// references.
|
||||
webviews: RefCell<HashMap<WebViewId, Weak<RefCell<WebViewInner>>>>,
|
||||
webviews: RefCell<FxHashMap<WebViewId, Weak<RefCell<WebViewInner>>>>,
|
||||
servo_errors: ServoErrorChannel,
|
||||
/// For single-process Servo instances, this field controls the initialization
|
||||
/// and deinitialization of the JS Engine. Multiprocess Servo instances have their
|
||||
|
|
|
@ -19,11 +19,11 @@ webxr = ["dep:webxr", "dep:webxr-api"]
|
|||
base = { workspace = true }
|
||||
bitflags = { workspace = true }
|
||||
byteorder = { workspace = true }
|
||||
rustc-hash = { workspace = true }
|
||||
canvas_traits = { workspace = true }
|
||||
compositing_traits = { workspace = true }
|
||||
crossbeam-channel = { workspace = true }
|
||||
euclid = { workspace = true }
|
||||
fnv = { workspace = true }
|
||||
glow = { workspace = true }
|
||||
half = "2"
|
||||
ipc-channel = { workspace = true }
|
||||
|
|
|
@ -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::default::Default;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
|
@ -13,8 +12,8 @@ use compositing_traits::{
|
|||
WebrenderExternalImageRegistry,
|
||||
};
|
||||
use euclid::default::Size2D;
|
||||
use fnv::FnvHashMap;
|
||||
use log::debug;
|
||||
use rustc_hash::FxHashMap;
|
||||
use surfman::chains::{SwapChainAPI, SwapChains, SwapChainsAPI};
|
||||
use surfman::{Device, SurfaceTexture};
|
||||
use webrender::RenderApiSender;
|
||||
|
@ -87,7 +86,7 @@ impl WebGLComm {
|
|||
struct WebGLExternalImages {
|
||||
rendering_context: Rc<dyn RenderingContext>,
|
||||
swap_chains: SwapChains<WebGLContextId, Device>,
|
||||
locked_front_buffers: FnvHashMap<WebGLContextId, SurfaceTexture>,
|
||||
locked_front_buffers: FxHashMap<WebGLContextId, SurfaceTexture>,
|
||||
}
|
||||
|
||||
impl WebGLExternalImages {
|
||||
|
@ -98,7 +97,7 @@ impl WebGLExternalImages {
|
|||
Self {
|
||||
rendering_context,
|
||||
swap_chains,
|
||||
locked_front_buffers: FnvHashMap::default(),
|
||||
locked_front_buffers: FxHashMap::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ use compositing_traits::{
|
|||
WebrenderImageHandlerType,
|
||||
};
|
||||
use euclid::default::Size2D;
|
||||
use fnv::FnvHashMap;
|
||||
use glow::{
|
||||
self as gl, ActiveTransformFeedback, Context as Gl, HasContext, NativeTransformFeedback,
|
||||
NativeUniformLocation, NativeVertexArray, PixelUnpackData, ShaderPrecisionFormat,
|
||||
|
@ -40,6 +39,7 @@ use ipc_channel::ipc::IpcSharedMemory;
|
|||
use itertools::Itertools;
|
||||
use log::{debug, error, trace, warn};
|
||||
use pixels::{self, PixelFormat, SnapshotAlphaMode, unmultiply_inplace};
|
||||
use rustc_hash::FxHashMap;
|
||||
use surfman::chains::{PreserveBuffer, SwapChains, SwapChainsAPI};
|
||||
use surfman::{
|
||||
self, Adapter, Connection, Context, ContextAttributeFlags, ContextAttributes, Device,
|
||||
|
@ -210,9 +210,9 @@ pub(crate) struct WebGLThread {
|
|||
compositor_api: CrossProcessCompositorApi,
|
||||
webrender_api: RenderApi,
|
||||
/// Map of live WebGLContexts.
|
||||
contexts: FnvHashMap<WebGLContextId, GLContextData>,
|
||||
contexts: FxHashMap<WebGLContextId, GLContextData>,
|
||||
/// Cached information for WebGLContexts.
|
||||
cached_context_info: FnvHashMap<WebGLContextId, WebGLContextInfo>,
|
||||
cached_context_info: FxHashMap<WebGLContextId, WebGLContextInfo>,
|
||||
/// Current bound context.
|
||||
bound_context_id: Option<WebGLContextId>,
|
||||
/// List of registered webrender external images.
|
||||
|
@ -863,7 +863,7 @@ impl WebGLThread {
|
|||
pub(crate) fn make_current_if_needed<'a>(
|
||||
device: &Device,
|
||||
context_id: WebGLContextId,
|
||||
contexts: &'a FnvHashMap<WebGLContextId, GLContextData>,
|
||||
contexts: &'a FxHashMap<WebGLContextId, GLContextData>,
|
||||
bound_id: &mut Option<WebGLContextId>,
|
||||
) -> Option<&'a GLContextData> {
|
||||
let data = contexts.get(&context_id);
|
||||
|
@ -882,7 +882,7 @@ impl WebGLThread {
|
|||
pub(crate) fn make_current_if_needed_mut<'a>(
|
||||
device: &Device,
|
||||
context_id: WebGLContextId,
|
||||
contexts: &'a mut FnvHashMap<WebGLContextId, GLContextData>,
|
||||
contexts: &'a mut FxHashMap<WebGLContextId, GLContextData>,
|
||||
bound_id: &mut Option<WebGLContextId>,
|
||||
) -> Option<&'a mut GLContextData> {
|
||||
let data = contexts.get_mut(&context_id);
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::num::NonZeroU32;
|
|||
use canvas_traits::webgl::{
|
||||
WebGLContextId, WebGLMsg, WebGLSender, WebXRCommand, WebXRLayerManagerId, webgl_channel,
|
||||
};
|
||||
use fnv::FnvHashMap;
|
||||
use rustc_hash::FxHashMap;
|
||||
use surfman::{Context, Device};
|
||||
use webxr::SurfmanGL as WebXRSurfman;
|
||||
use webxr_api::{
|
||||
|
@ -310,7 +310,7 @@ impl Drop for WebXRBridgeManager {
|
|||
}
|
||||
|
||||
pub(crate) struct WebXRBridgeContexts<'a> {
|
||||
pub(crate) contexts: &'a mut FnvHashMap<WebGLContextId, GLContextData>,
|
||||
pub(crate) contexts: &'a mut FxHashMap<WebGLContextId, GLContextData>,
|
||||
pub(crate) bound_context_id: &'a mut Option<WebGLContextId>,
|
||||
}
|
||||
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue