Skip to content

Commit 313afce

Browse files
committed
Use rustc' FxHasher instead of the std one
1 parent a88f946 commit 313afce

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

Cargo.lock

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

crates/syn2mas/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ compact_str.workspace = true
2424
tracing.workspace = true
2525
tracing-indicatif.workspace = true
2626
futures-util = "0.3.30"
27+
rustc-hash = "2.1.0"
2728

2829
rand.workspace = true
2930
uuid = "1.10.0"

crates/syn2mas/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ mod synapse_reader;
99
mod migration;
1010
mod progress_stream;
1111

12+
type RandomState = rustc_hash::FxBuildHasher;
13+
type HashMap<K, V> = rustc_hash::FxHashMap<K, V>;
14+
type HashSet<T> = rustc_hash::FxHashSet<T>;
15+
1216
pub use self::{
1317
mas_writer::{checks::mas_pre_migration_checks, locking::LockedMasDatabase, MasWriter},
1418
migration::migrate,

crates/syn2mas/src/migration.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111
//! This module does not implement any of the safety checks that should be run
1212
//! *before* the migration.
1313
14-
use std::{
15-
collections::{HashMap, HashSet},
16-
pin::pin,
17-
time::Instant,
18-
};
14+
use std::{pin::pin, time::Instant};
1915

2016
use chrono::{DateTime, Utc};
2117
use compact_str::CompactString;
@@ -40,7 +36,7 @@ use crate::{
4036
self, ExtractLocalpartError, FullUserId, SynapseAccessToken, SynapseDevice,
4137
SynapseExternalId, SynapseRefreshableTokenPair, SynapseThreepid, SynapseUser,
4238
},
43-
SynapseReader,
39+
HashMap, HashSet, RandomState, SynapseReader,
4440
};
4541

4642
#[derive(Debug, Error, ContextInto)]
@@ -100,7 +96,7 @@ pub async fn migrate(
10096
server_name: &str,
10197
clock: &dyn Clock,
10298
rng: &mut impl RngCore,
103-
provider_id_mapping: &HashMap<String, Uuid>,
99+
provider_id_mapping: &std::collections::HashMap<String, Uuid>,
104100
) -> Result<(), Error> {
105101
let span = Span::current();
106102
span.pb_set_message("counting work");
@@ -154,12 +150,13 @@ pub async fn migrate(
154150

155151
// `(MAS user_id, device_id)` mapped to `compat_session` ULID
156152
let mut devices_to_compat_sessions: HashMap<(Uuid, CompactString), Uuid> =
157-
HashMap::with_capacity(
153+
HashMap::with_capacity_and_hasher(
158154
usize::try_from(counts.devices)
159155
.expect("More than usize::MAX devices — unable to handle this many!")
160156
// Oversize the capacity, because the count is only an estimate and
161157
// we would like to avoid a reallocation
162158
* 9 / 8,
159+
RandomState::default(),
163160
);
164161

165162
span.pb_set_message("migrating access tokens");
@@ -249,8 +246,9 @@ async fn migrate_users(
249246
.with_progress_bar(user_count_hint as u64, 10_000));
250247
// Oversize the capacity, because the count is only an estimate and
251248
// we would like to avoid a reallocation
252-
let mut user_localparts_to_uuid = HashMap::with_capacity(user_count_hint * 9 / 8);
253-
let mut synapse_admins = HashSet::new();
249+
let mut user_localparts_to_uuid =
250+
HashMap::with_capacity_and_hasher(user_count_hint * 9 / 8, RandomState::default());
251+
let mut synapse_admins = HashSet::with_hasher(RandomState::default());
254252

255253
while let Some(user_res) = users_stream.next().await {
256254
let user = user_res.into_synapse("reading user")?;
@@ -401,7 +399,7 @@ async fn migrate_external_ids(
401399
server_name: &str,
402400
rng: &mut impl RngCore,
403401
user_localparts_to_uuid: &HashMap<CompactString, Uuid>,
404-
provider_id_mapping: &HashMap<String, Uuid>,
402+
provider_id_mapping: &std::collections::HashMap<String, Uuid>,
405403
) -> Result<(), Error> {
406404
let start = Instant::now();
407405

0 commit comments

Comments
 (0)