Skip to content

Commit d8d0445

Browse files
committed
bump hashbrown, foldhash; fix some compile errors in master
1 parent de142d4 commit d8d0445

File tree

22 files changed

+83
-68
lines changed

22 files changed

+83
-68
lines changed

Cargo.lock

Lines changed: 20 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ env_logger = "0.10"
179179
ethnum = { version = "1.5.0", features = ["serde"] }
180180
flate2 = "1.0.24"
181181
flume = { version = "0.11", default-features = false, features = ["async"] }
182-
foldhash = "0.1.4"
182+
foldhash = "0.2.0"
183183
fs-err = "2.9.0"
184184
fs_extra = "1.3.0"
185185
fs2 = "0.4.3"
@@ -189,7 +189,7 @@ futures-util = "0.3"
189189
getrandom02 = { package = "getrandom", version = "0.2" }
190190
git2 = "0.19"
191191
glob = "0.3.1"
192-
hashbrown = { version = "0.15", default-features = false, features = ["equivalent", "inline-more"] }
192+
hashbrown = { version = "0.16.1", default-features = false, features = ["equivalent", "inline-more", "rayon", "serde"] }
193193
headers = "0.4"
194194
heck = "0.4"
195195
hex = "0.4.3"

crates/bench/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ spacetimedb-standalone = { path = "../standalone" }
5252
spacetimedb-table = { path = "../table" }
5353
spacetimedb-testing = { path = "../testing" }
5454

55+
ahash.workspace = true
5556
anyhow.workspace = true
5657
anymap.workspace = true
5758
byte-unit.workspace = true
5859
clap.workspace = true
5960
criterion.workspace = true
6061
futures.workspace = true
6162
foldhash.workspace = true
63+
hashbrown.workspace = true
6264
lazy_static.workspace = true
6365
log.workspace = true
6466
mimalloc.workspace = true

crates/bench/benches/index.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use core::{hint::black_box, iter::repeat_with, time::Duration};
1+
use core::{hash::BuildHasherDefault, hint::black_box, iter::repeat_with, time::Duration};
22
use criterion::{
33
criterion_group, criterion_main,
44
measurement::{Measurement as _, WallTime},
55
BenchmarkGroup, Criterion,
66
};
77
use foldhash::{HashSet, HashSetExt};
8+
use hashbrown::{hash_map::Entry, HashMap};
89
use itertools::Itertools as _;
9-
use spacetimedb_data_structures::map::{Entry, HashMap};
1010
use spacetimedb_sats::layout::Size;
1111
use spacetimedb_table::indexes::{PageIndex, PageOffset, RowPointer, SquashedOffset};
1212
use spacetimedb_table::table_index::unique_direct_index::UniqueDirectIndex;
@@ -191,7 +191,7 @@ impl Index for IBTree {
191191
}
192192

193193
#[derive(Clone)]
194-
struct IAHash(HashMap<K, RowPointer>);
194+
struct IAHash(HashMap<K, RowPointer, BuildHasherDefault<ahash::AHasher>>);
195195
impl Index for IAHash {
196196
const NAME: &'static str = "IAHash";
197197
fn new() -> Self {

crates/core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ flume.workspace = true
6060
fs2.workspace = true
6161
futures.workspace = true
6262
futures-util.workspace = true
63-
hashbrown = { workspace = true, features = ["rayon", "serde"] }
6463
hex.workspace = true
6564
hostname.workspace = true
6665
http.workspace = true

crates/core/src/subscription/delta.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use anyhow::Result;
2-
use hashbrown::HashMap;
2+
use spacetimedb_data_structures::map::{HashCollectionExt as _, HashMap};
33
use spacetimedb_execution::{Datastore, DeltaStore};
44
use spacetimedb_lib::metrics::ExecutionMetrics;
55
use spacetimedb_subscription::SubscriptionPlan;

crates/core/src/subscription/module_subscription_actor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,6 @@ mod tests {
12251225
use crate::subscription::query::compile_read_only_query;
12261226
use crate::subscription::TableUpdateType;
12271227
use core::fmt;
1228-
use hashbrown::HashMap;
12291228
use itertools::Itertools;
12301229
use pretty_assertions::assert_matches;
12311230
use spacetimedb_client_api_messages::energy::EnergyQuanta;
@@ -1234,6 +1233,7 @@ mod tests {
12341233
TableUpdate, Unsubscribe, UnsubscribeMulti,
12351234
};
12361235
use spacetimedb_commitlog::{commitlog, repo};
1236+
use spacetimedb_data_structures::map::{HashCollectionExt as _, HashMap};
12371237
use spacetimedb_datastore::system_tables::{StRowLevelSecurityRow, ST_ROW_LEVEL_SECURITY_ID};
12381238
use spacetimedb_durability::{Durability, EmptyHistory, TxOffset};
12391239
use spacetimedb_execution::dml::MutDatastore;

crates/core/src/subscription/module_subscription_manager.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ use crate::subscription::delta::eval_delta;
1212
use crate::subscription::websocket_building::BuildableWebsocketFormat;
1313
use crate::worker_metrics::WORKER_METRICS;
1414
use core::mem;
15-
use hashbrown::hash_map::OccupiedError;
16-
use hashbrown::{HashMap, HashSet};
1715
use parking_lot::RwLock;
1816
use prometheus::IntGauge;
1917
use spacetimedb_client_api_messages::websocket::{
2018
BsatnFormat, CompressableQueryUpdate, FormatSwitch, JsonFormat, QueryId, QueryUpdate, SingleQueryUpdate,
2119
};
22-
use spacetimedb_data_structures::map::{Entry, IntMap};
20+
use spacetimedb_data_structures::map::HashCollectionExt as _;
21+
use spacetimedb_data_structures::map::{
22+
hash_map::{Entry, OccupiedError},
23+
HashMap, HashSet, IntMap,
24+
};
2325
use spacetimedb_datastore::locking_tx_datastore::state_view::StateView;
2426
use spacetimedb_durability::TxOffset;
2527
use spacetimedb_expr::expr::CollectViews;

crates/core/src/subscription/tx.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
use std::{
2-
collections::BTreeMap,
3-
ops::{Deref, RangeBounds},
4-
sync::Arc,
5-
};
6-
7-
use hashbrown::HashMap;
1+
use super::module_subscription_manager::QueriedTableIndexIds;
82
use itertools::Either;
93
use smallvec::SmallVec;
4+
use spacetimedb_data_structures::map::{HashCollectionExt as _, HashMap};
5+
use spacetimedb_datastore::{
6+
locking_tx_datastore::{state_view::StateView, TxId},
7+
traits::TxData,
8+
};
109
use spacetimedb_execution::{Datastore, DeltaStore, Row};
1110
use spacetimedb_lib::{query::Delta, AlgebraicValue, ProductValue};
1211
use spacetimedb_primitives::{IndexId, TableId};
1312
use spacetimedb_table::table::{IndexScanRangeIter, TableScanIter};
14-
15-
use spacetimedb_datastore::{
16-
locking_tx_datastore::{state_view::StateView, TxId},
17-
traits::TxData,
13+
use std::{
14+
collections::BTreeMap,
15+
ops::{Deref, RangeBounds},
16+
sync::Arc,
1817
};
1918

20-
use super::module_subscription_manager::QueriedTableIndexIds;
21-
2219
/// If an index is defined on a set of columns,
2320
/// and if that index is used in a subscription query,
2421
/// we build the very same index for each delta table.

crates/data-structures/src/map.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
use core::hash::{BuildHasher, BuildHasherDefault};
2-
pub use hashbrown::hash_map::Entry;
32
use nohash_hasher::BuildNoHashHasher;
3+
4+
pub use hashbrown::Equivalent;
45
pub use nohash_hasher::IsEnabled as ValidAsIdentityHash;
56

7+
pub mod hash_set {
8+
pub use super::HashSet;
9+
pub use hashbrown::hash_set::*;
10+
}
11+
12+
pub mod hash_map {
13+
pub use super::HashMap;
14+
pub use hashbrown::hash_map::*;
15+
}
16+
617
pub type DefaultHashBuilder = BuildHasherDefault<ahash::AHasher>;
718
// TODO(centril): expose two maps instead,
819
// one `map::fast::HashMap` and one `map::ddos::HashMap`.
920
// In the first case we won't care about DDoS protection at all and can use `foldhash::fast`.
1021
// In the lattr, we can use e.g., randomized AHash.
11-
pub type HashMap<K, V, S = DefaultHashBuilder> = hashbrown::HashMap<K, V, S>;
12-
pub type HashSet<T, S = DefaultHashBuilder> = hashbrown::HashSet<T, S>;
22+
pub type HashMap<K, V> = hashbrown::HashMap<K, V, DefaultHashBuilder>;
23+
pub type HashSet<T> = hashbrown::HashSet<T, DefaultHashBuilder>;
1324

1425
/// A version of [`HashMap<K, V>`] using the identity hash function,
1526
/// which is valid for any key type that can be converted to a `u64` without truncation.
16-
pub type IntMap<K, V> = HashMap<K, V, BuildNoHashHasher<K>>;
27+
pub type IntMap<K, V> = hashbrown::HashMap<K, V, BuildNoHashHasher<K>>;
1728

1829
/// A version of [`HashSet<K>`] using the identity hash function,
1930
/// which is valid for any key type that can be converted to a `u64` without truncation.
20-
pub type IntSet<K> = HashSet<K, BuildNoHashHasher<K>>;
31+
pub type IntSet<K> = hashbrown::HashSet<K, BuildNoHashHasher<K>>;
2132

2233
pub trait HashCollectionExt {
2334
/// Returns a new collection with default capacity, using `S::default()` to build the hasher.
@@ -27,22 +38,22 @@ pub trait HashCollectionExt {
2738
fn with_capacity(capacity: usize) -> Self;
2839
}
2940

30-
impl<K, V, S: BuildHasher + Default> HashCollectionExt for HashMap<K, V, S> {
41+
impl<K, V, S: BuildHasher + Default> HashCollectionExt for hashbrown::HashMap<K, V, S> {
3142
fn new() -> Self {
32-
HashMap::with_hasher(S::default())
43+
Self::with_hasher(S::default())
3344
}
3445

3546
fn with_capacity(capacity: usize) -> Self {
36-
HashMap::with_capacity_and_hasher(capacity, S::default())
47+
Self::with_capacity_and_hasher(capacity, S::default())
3748
}
3849
}
3950

40-
impl<K, S: BuildHasher + Default> HashCollectionExt for HashSet<K, S> {
51+
impl<K, S: BuildHasher + Default> HashCollectionExt for hashbrown::HashSet<K, S> {
4152
fn new() -> Self {
42-
HashSet::with_hasher(S::default())
53+
Self::with_hasher(S::default())
4354
}
4455

4556
fn with_capacity(capacity: usize) -> Self {
46-
HashSet::with_capacity_and_hasher(capacity, S::default())
57+
Self::with_capacity_and_hasher(capacity, S::default())
4758
}
4859
}

0 commit comments

Comments
 (0)