From 72e772be164195e2c5fafcdb9502831357bb4b94 Mon Sep 17 00:00:00 2001 From: Kenneth Loeffler Date: Thu, 31 Oct 2024 05:43:05 +0000 Subject: [PATCH] Use ahash for most HashMaps and HashSets (#466) --- rbx_binary/Cargo.toml | 1 + rbx_binary/src/deserializer/state.rs | 8 ++------ rbx_binary/src/serializer/state.rs | 3 ++- rbx_dom_weak/CHANGELOG.md | 8 ++++++++ rbx_dom_weak/Cargo.toml | 1 + rbx_dom_weak/src/dom.rs | 3 ++- rbx_xml/Cargo.toml | 1 + rbx_xml/src/deserializer.rs | 6 ++---- rbx_xml/src/serializer.rs | 7 ++----- 9 files changed, 21 insertions(+), 17 deletions(-) diff --git a/rbx_binary/Cargo.toml b/rbx_binary/Cargo.toml index 944c8e5e..840fc7f3 100644 --- a/rbx_binary/Cargo.toml +++ b/rbx_binary/Cargo.toml @@ -18,6 +18,7 @@ rbx_dom_weak = { version = "2.9.0", path = "../rbx_dom_weak" } rbx_reflection = { version = "4.7.0", path = "../rbx_reflection" } rbx_reflection_database = { version = "0.2.12", path = "../rbx_reflection_database" } +ahash = "0.8.11" log = "0.4.17" lz4 = "1.23.3" thiserror = "1.0.31" diff --git a/rbx_binary/src/deserializer/state.rs b/rbx_binary/src/deserializer/state.rs index 172287f3..f47796c3 100644 --- a/rbx_binary/src/deserializer/state.rs +++ b/rbx_binary/src/deserializer/state.rs @@ -1,10 +1,6 @@ -use std::{ - borrow::Cow, - collections::{HashMap, HashSet, VecDeque}, - convert::TryInto, - io::Read, -}; +use std::{borrow::Cow, collections::VecDeque, convert::TryInto, io::Read}; +use ahash::{HashMap, HashMapExt, HashSet, HashSetExt}; use rbx_dom_weak::{ types::{ Attributes, Axes, BinaryString, BrickColor, CFrame, Color3, Color3uint8, ColorSequence, diff --git a/rbx_binary/src/serializer/state.rs b/rbx_binary/src/serializer/state.rs index a068cca7..ac5b70a9 100644 --- a/rbx_binary/src/serializer/state.rs +++ b/rbx_binary/src/serializer/state.rs @@ -1,10 +1,11 @@ use std::{ borrow::{Borrow, Cow}, - collections::{btree_map, BTreeMap, BTreeSet, HashMap, HashSet}, + collections::{btree_map, BTreeMap, BTreeSet}, convert::TryInto, io::Write, }; +use ahash::{HashMap, HashMapExt, HashSet, HashSetExt}; use rbx_dom_weak::{ types::{ Attributes, Axes, BinaryString, BrickColor, CFrame, Color3, Color3uint8, ColorSequence, diff --git a/rbx_dom_weak/CHANGELOG.md b/rbx_dom_weak/CHANGELOG.md index f1a05354..27d245cb 100644 --- a/rbx_dom_weak/CHANGELOG.md +++ b/rbx_dom_weak/CHANGELOG.md @@ -89,6 +89,14 @@ where V: Into, I: IntoIterator, ``` +* Started using [ahash](https://docs.rs/ahash/latest/ahash/) for hash maps, consequently changing the signature of `WeakDom::into_raw` from +```rust +pub fn into_raw(self) -> (Ref, HashMap) { +``` +to +```rust +pub fn into_raw(self) -> (Ref, HashMap) { +``` ### Other changes * Added `UstrMapExt`, a helper trait providing convenience methods `UstrMap::new` and `UstrMap::with_capacity`. diff --git a/rbx_dom_weak/Cargo.toml b/rbx_dom_weak/Cargo.toml index 64d4cdb1..d77f9b7b 100644 --- a/rbx_dom_weak/Cargo.toml +++ b/rbx_dom_weak/Cargo.toml @@ -14,6 +14,7 @@ edition = "2018" rbx_types = { version = "1.10.0", path = "../rbx_types", features = ["serde"] } ustr = { version = "1.1.0", features = ["serde"] } +ahash = "0.8.11" serde = "1.0.137" [dev-dependencies] diff --git a/rbx_dom_weak/src/dom.rs b/rbx_dom_weak/src/dom.rs index a9e4fa42..ef93d495 100644 --- a/rbx_dom_weak/src/dom.rs +++ b/rbx_dom_weak/src/dom.rs @@ -1,5 +1,6 @@ -use std::collections::{HashMap, HashSet, VecDeque}; +use std::collections::VecDeque; +use ahash::{HashMap, HashMapExt, HashSet, HashSetExt}; use rbx_types::{Ref, UniqueId, Variant}; use ustr::ustr; diff --git a/rbx_xml/Cargo.toml b/rbx_xml/Cargo.toml index bedf265f..75164fed 100644 --- a/rbx_xml/Cargo.toml +++ b/rbx_xml/Cargo.toml @@ -15,6 +15,7 @@ rbx_dom_weak = { version = "2.9.0", path = "../rbx_dom_weak" } rbx_reflection = { version = "4.7.0", path = "../rbx_reflection" } rbx_reflection_database = { version = "0.2.12", path = "../rbx_reflection_database" } +ahash = "0.8.11" base64 = "0.13.0" log = "0.4.17" xml-rs = "0.8.4" diff --git a/rbx_xml/src/deserializer.rs b/rbx_xml/src/deserializer.rs index ec4dc876..7eb52fba 100644 --- a/rbx_xml/src/deserializer.rs +++ b/rbx_xml/src/deserializer.rs @@ -1,8 +1,6 @@ -use std::{ - collections::{hash_map::Entry, HashMap, HashSet}, - io::Read, -}; +use std::{collections::hash_map::Entry, io::Read}; +use ahash::{HashMap, HashMapExt, HashSet, HashSetExt}; use log::trace; use rbx_dom_weak::{ types::{Ref, SharedString, Variant, VariantType}, diff --git a/rbx_xml/src/serializer.rs b/rbx_xml/src/serializer.rs index d4fcf8fb..652a5f5f 100644 --- a/rbx_xml/src/serializer.rs +++ b/rbx_xml/src/serializer.rs @@ -1,9 +1,6 @@ -use std::{ - borrow::Cow, - collections::{BTreeMap, HashMap}, - io::Write, -}; +use std::{borrow::Cow, collections::BTreeMap, io::Write}; +use ahash::{HashMap, HashMapExt}; use rbx_dom_weak::{ types::{Ref, SharedString, SharedStringHash, Variant, VariantType}, WeakDom,