diff --git a/Cargo.lock b/Cargo.lock index ecdec9a6f..8e2cc8405 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6108,6 +6108,7 @@ dependencies = [ "mas-storage", "mas-storage-pg", "rand", + "rustc-hash 2.1.1", "serde", "sqlx", "thiserror 2.0.11", diff --git a/crates/syn2mas/Cargo.toml b/crates/syn2mas/Cargo.toml index 5b80b1510..578f705d2 100644 --- a/crates/syn2mas/Cargo.toml +++ b/crates/syn2mas/Cargo.toml @@ -23,6 +23,7 @@ chrono.workspace = true compact_str.workspace = true tracing.workspace = true futures-util = "0.3.31" +rustc-hash = "2.1.1" rand.workspace = true uuid = "1.15.1" diff --git a/crates/syn2mas/src/lib.rs b/crates/syn2mas/src/lib.rs index a7a4b72ca..d0d1162fb 100644 --- a/crates/syn2mas/src/lib.rs +++ b/crates/syn2mas/src/lib.rs @@ -8,6 +8,9 @@ mod synapse_reader; mod migration; +type RandomState = rustc_hash::FxBuildHasher; +type HashMap = rustc_hash::FxHashMap; + pub use self::{ mas_writer::{MasWriter, checks::mas_pre_migration_checks, locking::LockedMasDatabase}, migration::migrate, diff --git a/crates/syn2mas/src/migration.rs b/crates/syn2mas/src/migration.rs index f39c4a852..294baf0fc 100644 --- a/crates/syn2mas/src/migration.rs +++ b/crates/syn2mas/src/migration.rs @@ -11,7 +11,7 @@ //! This module does not implement any of the safety checks that should be run //! *before* the migration. -use std::{collections::HashMap, pin::pin, time::Instant}; +use std::{pin::pin, time::Instant}; use chrono::{DateTime, Utc}; use compact_str::CompactString; @@ -25,7 +25,7 @@ use ulid::Ulid; use uuid::{NonNilUuid, Uuid}; use crate::{ - SynapseReader, + HashMap, RandomState, SynapseReader, mas_writer::{ self, MasNewCompatAccessToken, MasNewCompatRefreshToken, MasNewCompatSession, MasNewEmailThreepid, MasNewUnsupportedThreepid, MasNewUpstreamOauthLink, MasNewUser, @@ -114,7 +114,7 @@ struct MigrationState { /// A mapping of Synapse external ID providers to MAS upstream OAuth 2.0 /// provider ID - provider_id_mapping: HashMap, + provider_id_mapping: std::collections::HashMap, } /// Performs a migration from Synapse's database to MAS' database. @@ -136,7 +136,7 @@ pub async fn migrate( server_name: String, clock: &dyn Clock, rng: &mut impl RngCore, - provider_id_mapping: HashMap, + provider_id_mapping: std::collections::HashMap, ) -> Result<(), Error> { let counts = synapse.count_rows().await.into_synapse("counting users")?; @@ -144,8 +144,11 @@ pub async fn migrate( server_name, // We oversize the hashmaps, as the estimates are innaccurate, and we would like to avoid // reallocations. - users: HashMap::with_capacity(counts.users * 9 / 8), - devices_to_compat_sessions: HashMap::with_capacity(counts.devices * 9 / 8), + users: HashMap::with_capacity_and_hasher(counts.users * 9 / 8, RandomState::default()), + devices_to_compat_sessions: HashMap::with_capacity_and_hasher( + counts.devices * 9 / 8, + RandomState::default(), + ), provider_id_mapping, };