Skip to content

Commit

Permalink
Use ahash for most HashMaps and HashSets (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethloeffler authored Oct 31, 2024
1 parent 33b600f commit 72e772b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 17 deletions.
1 change: 1 addition & 0 deletions rbx_binary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 2 additions & 6 deletions rbx_binary/src/deserializer/state.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion rbx_binary/src/serializer/state.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 8 additions & 0 deletions rbx_dom_weak/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ where
V: Into<Variant>,
I: IntoIterator<Item = (K, V)>,
```
* 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<Ref, Instance, RandomState>) {
```
to
```rust
pub fn into_raw(self) -> (Ref, HashMap<Ref, Instance, ahash::RandomState>) {
```

### Other changes
* Added `UstrMapExt`, a helper trait providing convenience methods `UstrMap::new` and `UstrMap::with_capacity`.
Expand Down
1 change: 1 addition & 0 deletions rbx_dom_weak/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion rbx_dom_weak/src/dom.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
1 change: 1 addition & 0 deletions rbx_xml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions rbx_xml/src/deserializer.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
7 changes: 2 additions & 5 deletions rbx_xml/src/serializer.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 72e772b

Please sign in to comment.