Skip to content

Commit 6ecae34

Browse files
committed
Use rustc' FxHasher instead of the std one
1 parent 3af1dd4 commit 6ecae34

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
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
@@ -25,6 +25,7 @@ compact_str.workspace = true
2525
tracing.workspace = true
2626
tracing-indicatif.workspace = true
2727
futures-util = "0.3.30"
28+
rustc-hash = "2.1.1"
2829

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

crates/syn2mas/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ 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+
1215
pub use self::{
1316
mas_writer::{checks::mas_pre_migration_checks, locking::LockedMasDatabase, MasWriter},
1417
migration::migrate,

crates/syn2mas/src/migration.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +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::{collections::HashMap, pin::pin, time::Instant};
14+
use std::{pin::pin, time::Instant};
1515

1616
use chrono::{DateTime, Utc};
1717
use compact_str::CompactString;
@@ -36,7 +36,7 @@ use crate::{
3636
self, ExtractLocalpartError, FullUserId, SynapseAccessToken, SynapseDevice,
3737
SynapseExternalId, SynapseRefreshableTokenPair, SynapseThreepid, SynapseUser,
3838
},
39-
SynapseReader,
39+
HashMap, RandomState, SynapseReader,
4040
};
4141

4242
#[derive(Debug, Error, ContextInto)]
@@ -109,7 +109,7 @@ struct MigrationState {
109109

110110
/// A mapping of Synapse external ID providers to MAS upstream OAuth 2.0
111111
/// provider ID
112-
provider_id_mapping: HashMap<String, Uuid>,
112+
provider_id_mapping: std::collections::HashMap<String, Uuid>,
113113
}
114114

115115
/// Performs a migration from Synapse's database to MAS' database.
@@ -132,7 +132,7 @@ pub async fn migrate(
132132
server_name: String,
133133
clock: &dyn Clock,
134134
rng: &mut impl RngCore,
135-
provider_id_mapping: HashMap<String, Uuid>,
135+
provider_id_mapping: std::collections::HashMap<String, Uuid>,
136136
) -> Result<(), Error> {
137137
let span = Span::current();
138138
span.pb_set_message("counting work");
@@ -143,8 +143,11 @@ pub async fn migrate(
143143
server_name,
144144
// We oversize the hashmaps, as the estimates are innaccurate, and we would like to avoid
145145
// reallocations.
146-
users: HashMap::with_capacity(counts.users * 9 / 8),
147-
devices_to_compat_sessions: HashMap::with_capacity(counts.devices * 9 / 8),
146+
users: HashMap::with_capacity_and_hasher(counts.users * 9 / 8, RandomState::default()),
147+
devices_to_compat_sessions: HashMap::with_capacity_and_hasher(
148+
counts.devices * 9 / 8,
149+
RandomState::default(),
150+
),
148151
provider_id_mapping,
149152
};
150153

0 commit comments

Comments
 (0)