From 7e78ed2d1e263ba1b35d716a52e2e3cc2eccae42 Mon Sep 17 00:00:00 2001 From: kennethloeffler Date: Wed, 30 Oct 2024 00:06:51 +0000 Subject: [PATCH 1/5] Use AHashMap in place of most HashMaps --- rbx_binary/Cargo.toml | 1 + rbx_binary/src/deserializer/state.rs | 8 ++------ rbx_binary/src/serializer/state.rs | 3 ++- rbx_dom_weak/Cargo.toml | 1 + rbx_dom_weak/src/dom.rs | 3 ++- rbx_reflection/Cargo.toml | 1 + rbx_reflection/src/database.rs | 6 ++---- rbx_reflection/src/serde_util.rs | 3 ++- rbx_reflector/Cargo.toml | 1 + rbx_reflector/src/cli/generate.rs | 2 +- 10 files changed, 15 insertions(+), 14 deletions(-) diff --git a/rbx_binary/Cargo.toml b/rbx_binary/Cargo.toml index 944c8e5e7..840fc7f34 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 172287f34..f47796c3d 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 a068cca7f..ac5b70a92 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/Cargo.toml b/rbx_dom_weak/Cargo.toml index 64d4cdb15..d77f9b7be 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 a9e4fa423..ef93d495a 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_reflection/Cargo.toml b/rbx_reflection/Cargo.toml index 2770848bc..b5c09c8c8 100644 --- a/rbx_reflection/Cargo.toml +++ b/rbx_reflection/Cargo.toml @@ -13,5 +13,6 @@ edition = "2018" [dependencies] rbx_types = { version = "1.10.0", path = "../rbx_types", features = ["serde"] } +ahash = "0.8.11" serde = { version = "1.0.137", features = ["derive"] } thiserror = "1.0.31" diff --git a/rbx_reflection/src/database.rs b/rbx_reflection/src/database.rs index 26425e637..601bd70d8 100644 --- a/rbx_reflection/src/database.rs +++ b/rbx_reflection/src/database.rs @@ -2,11 +2,9 @@ // for most cases. #![allow(clippy::new_without_default)] -use std::{ - borrow::Cow, - collections::{HashMap, HashSet}, -}; +use std::borrow::Cow; +use ahash::{HashMap, HashMapExt, HashSet, HashSetExt}; use rbx_types::{Variant, VariantType}; use serde::{Deserialize, Serialize}; diff --git a/rbx_reflection/src/serde_util.rs b/rbx_reflection/src/serde_util.rs index d192f55c6..3c021bd34 100644 --- a/rbx_reflection/src/serde_util.rs +++ b/rbx_reflection/src/serde_util.rs @@ -1,8 +1,9 @@ use std::{ - collections::{BTreeMap, BTreeSet, HashMap, HashSet}, + collections::{BTreeMap, BTreeSet}, hash::Hash, }; +use ahash::{HashMap, HashSet}; use serde::{Serialize, Serializer}; pub(crate) fn ordered_map(value: &HashMap, serializer: S) -> Result diff --git a/rbx_reflector/Cargo.toml b/rbx_reflector/Cargo.toml index c52a1cf64..8bcd3da45 100644 --- a/rbx_reflector/Cargo.toml +++ b/rbx_reflector/Cargo.toml @@ -16,6 +16,7 @@ rbx_reflection = { path = "../rbx_reflection" } rbx_types = { path = "../rbx_types", features = ["serde"] } rbx_xml = { path = "../rbx_xml" } +ahash = "0.8.11" anyhow = "1.0.57" clap = { version = "4.1.4", features = ["derive"] } env_logger = "0.10.0" diff --git a/rbx_reflector/src/cli/generate.rs b/rbx_reflector/src/cli/generate.rs index 8cefc0f35..6eec39757 100644 --- a/rbx_reflector/src/cli/generate.rs +++ b/rbx_reflector/src/cli/generate.rs @@ -1,11 +1,11 @@ use std::{ borrow::Cow, - collections::{HashMap, HashSet}, fs::{self, File}, io::{BufWriter, Write}, path::PathBuf, }; +use ahash::{HashMap, HashMapExt, HashSet, HashSetExt}; use anyhow::{bail, Context}; use clap::Parser; use rbx_reflection::{ From f4bb8eab7cc48f52e9c28ce9d2d40e366f63e17e Mon Sep 17 00:00:00 2001 From: kennethloeffler Date: Wed, 30 Oct 2024 20:59:57 +0000 Subject: [PATCH 2/5] Use ahash in rbx_xml Might as well... --- rbx_xml/Cargo.toml | 1 + rbx_xml/src/deserializer.rs | 6 ++---- rbx_xml/src/serializer.rs | 7 ++----- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/rbx_xml/Cargo.toml b/rbx_xml/Cargo.toml index bedf265f5..75164fedd 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 ec4dc876c..7eb52fbaf 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 d4fcf8fb2..652a5f5f2 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, From 70e8cd2df03eaeffe4f6a5289c251471365103d3 Mon Sep 17 00:00:00 2001 From: kennethloeffler Date: Wed, 30 Oct 2024 21:10:19 +0000 Subject: [PATCH 3/5] Don't use ahash for reflection --- rbx_reflection/Cargo.toml | 1 - rbx_reflection/src/database.rs | 6 ++++-- rbx_reflection/src/serde_util.rs | 3 +-- rbx_reflector/Cargo.toml | 1 - rbx_reflector/src/cli/generate.rs | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/rbx_reflection/Cargo.toml b/rbx_reflection/Cargo.toml index b5c09c8c8..2770848bc 100644 --- a/rbx_reflection/Cargo.toml +++ b/rbx_reflection/Cargo.toml @@ -13,6 +13,5 @@ edition = "2018" [dependencies] rbx_types = { version = "1.10.0", path = "../rbx_types", features = ["serde"] } -ahash = "0.8.11" serde = { version = "1.0.137", features = ["derive"] } thiserror = "1.0.31" diff --git a/rbx_reflection/src/database.rs b/rbx_reflection/src/database.rs index 601bd70d8..26425e637 100644 --- a/rbx_reflection/src/database.rs +++ b/rbx_reflection/src/database.rs @@ -2,9 +2,11 @@ // for most cases. #![allow(clippy::new_without_default)] -use std::borrow::Cow; +use std::{ + borrow::Cow, + collections::{HashMap, HashSet}, +}; -use ahash::{HashMap, HashMapExt, HashSet, HashSetExt}; use rbx_types::{Variant, VariantType}; use serde::{Deserialize, Serialize}; diff --git a/rbx_reflection/src/serde_util.rs b/rbx_reflection/src/serde_util.rs index 3c021bd34..d192f55c6 100644 --- a/rbx_reflection/src/serde_util.rs +++ b/rbx_reflection/src/serde_util.rs @@ -1,9 +1,8 @@ use std::{ - collections::{BTreeMap, BTreeSet}, + collections::{BTreeMap, BTreeSet, HashMap, HashSet}, hash::Hash, }; -use ahash::{HashMap, HashSet}; use serde::{Serialize, Serializer}; pub(crate) fn ordered_map(value: &HashMap, serializer: S) -> Result diff --git a/rbx_reflector/Cargo.toml b/rbx_reflector/Cargo.toml index 8bcd3da45..c52a1cf64 100644 --- a/rbx_reflector/Cargo.toml +++ b/rbx_reflector/Cargo.toml @@ -16,7 +16,6 @@ rbx_reflection = { path = "../rbx_reflection" } rbx_types = { path = "../rbx_types", features = ["serde"] } rbx_xml = { path = "../rbx_xml" } -ahash = "0.8.11" anyhow = "1.0.57" clap = { version = "4.1.4", features = ["derive"] } env_logger = "0.10.0" diff --git a/rbx_reflector/src/cli/generate.rs b/rbx_reflector/src/cli/generate.rs index 6eec39757..8cefc0f35 100644 --- a/rbx_reflector/src/cli/generate.rs +++ b/rbx_reflector/src/cli/generate.rs @@ -1,11 +1,11 @@ use std::{ borrow::Cow, + collections::{HashMap, HashSet}, fs::{self, File}, io::{BufWriter, Write}, path::PathBuf, }; -use ahash::{HashMap, HashMapExt, HashSet, HashSetExt}; use anyhow::{bail, Context}; use clap::Parser; use rbx_reflection::{ From 77e6ac7d3ddc7e98cb8966e965bb2b860d2b7559 Mon Sep 17 00:00:00 2001 From: kennethloeffler Date: Wed, 30 Oct 2024 21:21:57 +0000 Subject: [PATCH 4/5] Update rbx_dom_weak changelog --- rbx_dom_weak/CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rbx_dom_weak/CHANGELOG.md b/rbx_dom_weak/CHANGELOG.md index f1a05354a..5e2537dd3 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/ustr/latest/ustr/) 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`. From 8e3c3f706964f6b20ce7dd6756a28dd632d942c2 Mon Sep 17 00:00:00 2001 From: Kenneth Loeffler Date: Wed, 30 Oct 2024 21:40:35 +0000 Subject: [PATCH 5/5] Update rbx_dom_weak/CHANGELOG.md Co-authored-by: Micah --- rbx_dom_weak/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rbx_dom_weak/CHANGELOG.md b/rbx_dom_weak/CHANGELOG.md index 5e2537dd3..27d245cbc 100644 --- a/rbx_dom_weak/CHANGELOG.md +++ b/rbx_dom_weak/CHANGELOG.md @@ -89,7 +89,7 @@ where V: Into, I: IntoIterator, ``` -* Started using [ahash](https://docs.rs/ustr/latest/ustr/) for hash maps, consequently changing the signature of `WeakDom::into_raw` from +* 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) { ```