Skip to content

Commit a2701c3

Browse files
committed
Use rustc' FxHasher instead of the std one
1 parent c7b09e6 commit a2701c3

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
@@ -16,7 +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::{collections::HashMap, pin::pin, time::Instant};
19+
use std::{pin::pin, time::Instant};
2020

2121
use chrono::{DateTime, Utc};
2222
use compact_str::CompactString;
@@ -41,7 +41,7 @@ use crate::{
4141
self, ExtractLocalpartError, FullUserId, SynapseAccessToken, SynapseDevice,
4242
SynapseExternalId, SynapseRefreshableTokenPair, SynapseThreepid, SynapseUser,
4343
},
44-
SynapseReader,
44+
HashMap, RandomState, SynapseReader,
4545
};
4646

4747
#[derive(Debug, Error, ContextInto)]
@@ -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.
@@ -137,7 +137,7 @@ pub async fn migrate(
137137
server_name: String,
138138
clock: &dyn Clock,
139139
rng: &mut impl RngCore,
140-
provider_id_mapping: HashMap<String, Uuid>,
140+
provider_id_mapping: std::collections::HashMap<String, Uuid>,
141141
) -> Result<(), Error> {
142142
let span = Span::current();
143143
span.pb_set_message("counting work");
@@ -148,8 +148,11 @@ pub async fn migrate(
148148
server_name,
149149
// We oversize the hashmaps, as the estimates are innaccurate, and we would like to avoid
150150
// reallocations.
151-
users: HashMap::with_capacity(counts.users * 9 / 8),
152-
devices_to_compat_sessions: HashMap::with_capacity(counts.devices * 9 / 8),
151+
users: HashMap::with_capacity_and_hasher(counts.users * 9 / 8, RandomState::default()),
152+
devices_to_compat_sessions: HashMap::with_capacity_and_hasher(
153+
counts.devices * 9 / 8,
154+
RandomState::default(),
155+
),
153156
provider_id_mapping,
154157
};
155158

0 commit comments

Comments
 (0)