Skip to content

Commit 9d12d0f

Browse files
sandhosereivilibre
authored andcommitted
Use rustc' FxHasher instead of the std one
1 parent 06a2ca3 commit 9d12d0f

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
@@ -23,6 +23,7 @@ chrono.workspace = true
2323
compact_str.workspace = true
2424
tracing.workspace = true
2525
futures-util = "0.3.31"
26+
rustc-hash = "2.1.1"
2627

2728
rand.workspace = true
2829
uuid = "1.15.1"

crates/syn2mas/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ mod synapse_reader;
88

99
mod migration;
1010

11+
type RandomState = rustc_hash::FxBuildHasher;
12+
type HashMap<K, V> = rustc_hash::FxHashMap<K, V>;
13+
1114
pub use self::{
1215
mas_writer::{MasWriter, checks::mas_pre_migration_checks, locking::LockedMasDatabase},
1316
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;
@@ -25,7 +25,7 @@ use ulid::Ulid;
2525
use uuid::{NonNilUuid, Uuid};
2626

2727
use crate::{
28-
SynapseReader,
28+
HashMap, RandomState, SynapseReader,
2929
mas_writer::{
3030
self, MasNewCompatAccessToken, MasNewCompatRefreshToken, MasNewCompatSession,
3131
MasNewEmailThreepid, MasNewUnsupportedThreepid, MasNewUpstreamOauthLink, MasNewUser,
@@ -114,7 +114,7 @@ struct MigrationState {
114114

115115
/// A mapping of Synapse external ID providers to MAS upstream OAuth 2.0
116116
/// provider ID
117-
provider_id_mapping: HashMap<String, Uuid>,
117+
provider_id_mapping: std::collections::HashMap<String, Uuid>,
118118
}
119119

120120
/// Performs a migration from Synapse's database to MAS' database.
@@ -136,16 +136,19 @@ pub async fn migrate(
136136
server_name: String,
137137
clock: &dyn Clock,
138138
rng: &mut impl RngCore,
139-
provider_id_mapping: HashMap<String, Uuid>,
139+
provider_id_mapping: std::collections::HashMap<String, Uuid>,
140140
) -> Result<(), Error> {
141141
let counts = synapse.count_rows().await.into_synapse("counting users")?;
142142

143143
let state = MigrationState {
144144
server_name,
145145
// We oversize the hashmaps, as the estimates are innaccurate, and we would like to avoid
146146
// reallocations.
147-
users: HashMap::with_capacity(counts.users * 9 / 8),
148-
devices_to_compat_sessions: HashMap::with_capacity(counts.devices * 9 / 8),
147+
users: HashMap::with_capacity_and_hasher(counts.users * 9 / 8, RandomState::default()),
148+
devices_to_compat_sessions: HashMap::with_capacity_and_hasher(
149+
counts.devices * 9 / 8,
150+
RandomState::default(),
151+
),
149152
provider_id_mapping,
150153
};
151154

0 commit comments

Comments
 (0)