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:
Narfinger 2025-09-09 10:33:46 +02:00 committed by GitHub
parent 1deb7b5957
commit 177f6d6502
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
46 changed files with 226 additions and 215 deletions

View file

@ -3,11 +3,11 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::cell::Cell;
use std::collections::HashMap;
use std::rc::Rc;
use dom_struct::dom_struct;
use js::rust::HandleObject;
use rustc_hash::FxHashMap;
use servo_media::ServoMedia;
use servo_media::streams::MediaStreamType;
use servo_media::streams::registry::MediaStreamId;
@ -73,7 +73,7 @@ pub(crate) struct RTCPeerConnection {
ice_connection_state: Cell<RTCIceConnectionState>,
signaling_state: Cell<RTCSignalingState>,
#[ignore_malloc_size_of = "defined in servo-media"]
data_channels: DomRefCell<HashMap<DataChannelId, Dom<RTCDataChannel>>>,
data_channels: DomRefCell<FxHashMap<DataChannelId, Dom<RTCDataChannel>>>,
}
struct RTCSignaller {
@ -171,7 +171,7 @@ impl RTCPeerConnection {
gathering_state: Cell::new(RTCIceGatheringState::New),
ice_connection_state: Cell::new(RTCIceConnectionState::New),
signaling_state: Cell::new(RTCSignalingState::Stable),
data_channels: DomRefCell::new(HashMap::new()),
data_channels: DomRefCell::new(FxHashMap::default()),
}
}