Skip to content

Commit 5918c37

Browse files
committed
Use rustc' FxHasher instead of the std one
1 parent d6db8ea commit 5918c37

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 0 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.1"
2728

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

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
@@ -16,11 +16,7 @@
1616
//! This module does not implement any of the safety checks that should be run
1717
//! *before* the migration.
1818
19-
use std::{
20-
collections::{HashMap, HashSet},
21-
pin::pin,
22-
time::Instant,
23-
};
19+
use std::{pin::pin, time::Instant};
2420

2521
use chrono::{DateTime, Utc};
2622
use compact_str::CompactString;
@@ -45,7 +41,7 @@ use crate::{
4541
self, ExtractLocalpartError, FullUserId, SynapseAccessToken, SynapseDevice,
4642
SynapseExternalId, SynapseRefreshableTokenPair, SynapseThreepid, SynapseUser,
4743
},
48-
SynapseReader,
44+
HashMap, HashSet, RandomState, SynapseReader,
4945
};
5046

5147
#[derive(Debug, Error, ContextInto)]
@@ -105,7 +101,7 @@ pub async fn migrate(
105101
server_name: &str,
106102
clock: &dyn Clock,
107103
rng: &mut impl RngCore,
108-
provider_id_mapping: &HashMap<String, Uuid>,
104+
provider_id_mapping: &std::collections::HashMap<String, Uuid>,
109105
) -> Result<(), Error> {
110106
let span = Span::current();
111107
span.pb_set_message("counting work");
@@ -159,12 +155,13 @@ pub async fn migrate(
159155

160156
// `(MAS user_id, device_id)` mapped to `compat_session` ULID
161157
let mut devices_to_compat_sessions: HashMap<(Uuid, CompactString), Uuid> =
162-
HashMap::with_capacity(
158+
HashMap::with_capacity_and_hasher(
163159
usize::try_from(counts.devices)
164160
.expect("More than usize::MAX devices — unable to handle this many!")
165161
// Oversize the capacity, because the count is only an estimate and
166162
// we would like to avoid a reallocation
167163
* 9 / 8,
164+
RandomState::default(),
168165
);
169166

170167
span.pb_set_message("migrating access tokens");
@@ -254,8 +251,9 @@ async fn migrate_users(
254251
.with_progress_bar(user_count_hint as u64, 10_000));
255252
// Oversize the capacity, because the count is only an estimate and
256253
// we would like to avoid a reallocation
257-
let mut user_localparts_to_uuid = HashMap::with_capacity(user_count_hint * 9 / 8);
258-
let mut synapse_admins = HashSet::new();
254+
let mut user_localparts_to_uuid =
255+
HashMap::with_capacity_and_hasher(user_count_hint * 9 / 8, RandomState::default());
256+
let mut synapse_admins = HashSet::with_hasher(RandomState::default());
259257

260258
while let Some(user_res) = users_stream.next().await {
261259
let user = user_res.into_synapse("reading user")?;
@@ -406,7 +404,7 @@ async fn migrate_external_ids(
406404
server_name: &str,
407405
rng: &mut impl RngCore,
408406
user_localparts_to_uuid: &HashMap<CompactString, Uuid>,
409-
provider_id_mapping: &HashMap<String, Uuid>,
407+
provider_id_mapping: &std::collections::HashMap<String, Uuid>,
410408
) -> Result<(), Error> {
411409
let start = Instant::now();
412410

0 commit comments

Comments
 (0)