mirror of
https://github.com/servo/servo.git
synced 2025-09-27 15:20:09 +01:00
Replace Hash Algorithm in HashMap/Set with FxHashMap/Set for simple types (#39166)
FxHash is faster than FnvHash and SipHash for simple types up to at least 64 bytes. The cryptographic guarantees are not needed for any types changed here because they are simple ids. This changes the types in script and net crates. In a future PR we will change the remaining Fnv to be also Fx unless there is a reason to keep them as Fnv. Testing: Should not change functionality but unit test and wpt will find it. Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This commit is contained in:
parent
1deb7b5957
commit
177f6d6502
46 changed files with 226 additions and 215 deletions
|
@ -31,6 +31,7 @@ data-url = { workspace = true }
|
|||
devtools_traits = { workspace = true }
|
||||
embedder_traits = { workspace = true }
|
||||
fst = "0.4"
|
||||
rustc-hash = { workspace = true }
|
||||
futures = { version = "0.3", package = "futures" }
|
||||
futures-core = { version = "0.3.30", default-features = false }
|
||||
futures-util = { version = "0.3.30", default-features = false }
|
||||
|
|
|
@ -59,6 +59,7 @@ use net_traits::{
|
|||
};
|
||||
use profile_traits::mem::{Report, ReportKind};
|
||||
use profile_traits::path;
|
||||
use rustc_hash::FxHashMap;
|
||||
use servo_arc::Arc;
|
||||
use servo_url::{Host, ImmutableOrigin, ServoUrl};
|
||||
use tokio::sync::mpsc::{
|
||||
|
@ -102,7 +103,7 @@ pub struct HttpState {
|
|||
/// or whether a concurrent pending store should be awaited.
|
||||
pub http_cache_state: HttpCacheState,
|
||||
pub auth_cache: RwLock<AuthCache>,
|
||||
pub history_states: RwLock<HashMap<HistoryStateId, Vec<u8>>>,
|
||||
pub history_states: RwLock<FxHashMap<HistoryStateId, Vec<u8>>>,
|
||||
pub client: Client<Connector, crate::connector::BoxedBody>,
|
||||
pub override_manager: CertificateErrorOverrideManager,
|
||||
pub embedder_proxy: Mutex<EmbedderProxy>,
|
||||
|
|
|
@ -27,6 +27,7 @@ use pixels::{CorsStatus, ImageFrame, ImageMetadata, PixelFormat, RasterImage, lo
|
|||
use profile_traits::mem::{Report, ReportKind};
|
||||
use profile_traits::path;
|
||||
use resvg::{tiny_skia, usvg};
|
||||
use rustc_hash::FxHashMap;
|
||||
use servo_config::pref;
|
||||
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||
use webrender_api::units::DeviceIntSize;
|
||||
|
@ -185,7 +186,7 @@ type ImageKey = (ServoUrl, ImmutableOrigin, Option<CorsSettings>);
|
|||
struct AllPendingLoads {
|
||||
// The loads, indexed by a load key. Used during most operations,
|
||||
// for performance reasons.
|
||||
loads: HashMap<LoadKey, PendingLoad>,
|
||||
loads: FxHashMap<LoadKey, PendingLoad>,
|
||||
|
||||
// Get a load key from its url and requesting origin. Used ony when starting and
|
||||
// finishing a load or when adding a new listener.
|
||||
|
@ -198,8 +199,8 @@ struct AllPendingLoads {
|
|||
impl AllPendingLoads {
|
||||
fn new() -> AllPendingLoads {
|
||||
AllPendingLoads {
|
||||
loads: HashMap::new(),
|
||||
url_to_load_key: HashMap::new(),
|
||||
loads: FxHashMap::default(),
|
||||
url_to_load_key: HashMap::default(),
|
||||
keygen: LoadKeyGenerator::new(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use net_traits::indexeddb_thread::{
|
|||
AsyncOperation, BackendError, BackendResult, CreateObjectResult, DbResult, IndexedDBThreadMsg,
|
||||
IndexedDBTxnMode, KeyPath, SyncOperation,
|
||||
};
|
||||
use rustc_hash::FxHashMap;
|
||||
use servo_config::pref;
|
||||
use servo_url::origin::ImmutableOrigin;
|
||||
use uuid::Uuid;
|
||||
|
@ -78,7 +79,7 @@ impl IndexedDBDescription {
|
|||
|
||||
struct IndexedDBEnvironment<E: KvsEngine> {
|
||||
engine: E,
|
||||
transactions: HashMap<u64, KvsTransaction>,
|
||||
transactions: FxHashMap<u64, KvsTransaction>,
|
||||
serial_number_counter: u64,
|
||||
}
|
||||
|
||||
|
@ -86,7 +87,7 @@ impl<E: KvsEngine> IndexedDBEnvironment<E> {
|
|||
fn new(engine: E) -> IndexedDBEnvironment<E> {
|
||||
IndexedDBEnvironment {
|
||||
engine,
|
||||
transactions: HashMap::new(),
|
||||
transactions: FxHashMap::default(),
|
||||
serial_number_counter: 0,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ use profile_traits::mem::{
|
|||
};
|
||||
use profile_traits::path;
|
||||
use profile_traits::time::ProfilerChan;
|
||||
use rustc_hash::FxHashMap;
|
||||
use rustls::RootCertStore;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_arc::Arc as ServoArc;
|
||||
|
@ -182,8 +183,8 @@ struct ResourceChannelManager {
|
|||
config_dir: Option<PathBuf>,
|
||||
ca_certificates: CACertificates,
|
||||
ignore_certificate_errors: bool,
|
||||
cancellation_listeners: HashMap<RequestId, Weak<CancellationListener>>,
|
||||
cookie_listeners: HashMap<CookieStoreId, IpcSender<CookieAsyncResponse>>,
|
||||
cancellation_listeners: FxHashMap<RequestId, Weak<CancellationListener>>,
|
||||
cookie_listeners: FxHashMap<CookieStoreId, IpcSender<CookieAsyncResponse>>,
|
||||
}
|
||||
|
||||
fn create_http_states(
|
||||
|
@ -207,7 +208,7 @@ fn create_http_states(
|
|||
hsts_list: RwLock::new(hsts_list),
|
||||
cookie_jar: RwLock::new(cookie_jar),
|
||||
auth_cache: RwLock::new(auth_cache),
|
||||
history_states: RwLock::new(HashMap::new()),
|
||||
history_states: RwLock::new(FxHashMap::default()),
|
||||
http_cache: RwLock::new(http_cache),
|
||||
http_cache_state: Mutex::new(HashMap::new()),
|
||||
client: create_http_client(create_tls_config(
|
||||
|
@ -224,7 +225,7 @@ fn create_http_states(
|
|||
hsts_list: RwLock::new(HstsList::default()),
|
||||
cookie_jar: RwLock::new(CookieStorage::new(150)),
|
||||
auth_cache: RwLock::new(AuthCache::default()),
|
||||
history_states: RwLock::new(HashMap::new()),
|
||||
history_states: RwLock::new(FxHashMap::default()),
|
||||
http_cache: RwLock::new(HttpCache::default()),
|
||||
http_cache_state: Mutex::new(HashMap::new()),
|
||||
client: create_http_client(create_tls_config(
|
||||
|
|
|
@ -15,6 +15,7 @@ use profile_traits::mem::{
|
|||
ProcessReports, ProfilerChan as MemProfilerChan, Report, ReportKind, perform_memory_report,
|
||||
};
|
||||
use profile_traits::path;
|
||||
use rustc_hash::FxHashMap;
|
||||
use servo_url::ServoUrl;
|
||||
|
||||
use crate::resource_thread;
|
||||
|
@ -52,7 +53,7 @@ type OriginEntry = (usize, BTreeMap<String, String>);
|
|||
|
||||
struct StorageManager {
|
||||
port: GenericReceiver<StorageThreadMsg>,
|
||||
session_data: HashMap<WebViewId, HashMap<String, OriginEntry>>,
|
||||
session_data: FxHashMap<WebViewId, HashMap<String, OriginEntry>>,
|
||||
local_data: HashMap<String, OriginEntry>,
|
||||
config_dir: Option<PathBuf>,
|
||||
}
|
||||
|
@ -65,7 +66,7 @@ impl StorageManager {
|
|||
}
|
||||
StorageManager {
|
||||
port,
|
||||
session_data: HashMap::new(),
|
||||
session_data: FxHashMap::default(),
|
||||
local_data,
|
||||
config_dir,
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ use net_traits::filemanager_thread::FileTokenCheck;
|
|||
use net_traits::request::Request;
|
||||
use net_traits::response::Response;
|
||||
use net_traits::{AsyncRuntime, FetchTaskTarget, ResourceFetchTiming, ResourceTimingType};
|
||||
use rustc_hash::FxHashMap;
|
||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
||||
use rustls_pki_types::{CertificateDer, PrivateKeyDer};
|
||||
use servo_arc::Arc as ServoArc;
|
||||
|
@ -146,7 +147,7 @@ fn create_http_state(fc: Option<EmbedderProxy>) -> HttpState {
|
|||
hsts_list: RwLock::new(net::hsts::HstsList::default()),
|
||||
cookie_jar: RwLock::new(net::cookie_storage::CookieStorage::new(150)),
|
||||
auth_cache: RwLock::new(net::resource_thread::AuthCache::default()),
|
||||
history_states: RwLock::new(HashMap::new()),
|
||||
history_states: RwLock::new(FxHashMap::default()),
|
||||
http_cache: RwLock::new(net::http_cache::HttpCache::default()),
|
||||
http_cache_state: Mutex::new(HashMap::new()),
|
||||
client: create_http_client(create_tls_config(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue