Use rustc' FxHasher instead of the std one

This commit is contained in:
Quentin Gliech
2025-02-03 13:53:22 +01:00
committed by Olivier 'reivilibre
parent 0b9036601a
commit c45500be72
4 changed files with 14 additions and 6 deletions

1
Cargo.lock generated
View File

@@ -6108,6 +6108,7 @@ dependencies = [
"mas-storage",
"mas-storage-pg",
"rand",
"rustc-hash 2.1.1",
"serde",
"sqlx",
"thiserror 2.0.11",

View File

@@ -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"

View File

@@ -8,6 +8,9 @@ mod synapse_reader;
mod migration;
type RandomState = rustc_hash::FxBuildHasher;
type HashMap<K, V> = rustc_hash::FxHashMap<K, V>;
pub use self::{
mas_writer::{MasWriter, checks::mas_pre_migration_checks, locking::LockedMasDatabase},
migration::migrate,

View File

@@ -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<String, Uuid>,
provider_id_mapping: std::collections::HashMap<String, Uuid>,
}
/// 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<String, Uuid>,
provider_id_mapping: std::collections::HashMap<String, Uuid>,
) -> 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,
};