Skip to content

Commit e403dd1

Browse files
committed
Use rustc' FxHasher instead of the std one
1 parent 0554e47 commit e403dd1

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.31"
28+
rustc-hash = "2.1.1"
2829

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

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::{MasWriter, checks::mas_pre_migration_checks, locking::LockedMasDatabase},
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;
@@ -26,7 +26,7 @@ use ulid::Ulid;
2626
use uuid::Uuid;
2727

2828
use crate::{
29-
SynapseReader,
29+
HashMap, RandomState, SynapseReader,
3030
mas_writer::{
3131
self, MasNewCompatAccessToken, MasNewCompatRefreshToken, MasNewCompatSession,
3232
MasNewEmailThreepid, MasNewUnsupportedThreepid, MasNewUpstreamOauthLink, MasNewUser,
@@ -116,7 +116,7 @@ struct MigrationState {
116116

117117
/// A mapping of Synapse external ID providers to MAS upstream OAuth 2.0
118118
/// provider ID
119-
provider_id_mapping: HashMap<String, Uuid>,
119+
provider_id_mapping: std::collections::HashMap<String, Uuid>,
120120
}
121121

122122
/// Performs a migration from Synapse's database to MAS' database.
@@ -139,7 +139,7 @@ pub async fn migrate(
139139
server_name: String,
140140
clock: &dyn Clock,
141141
rng: &mut impl RngCore,
142-
provider_id_mapping: HashMap<String, Uuid>,
142+
provider_id_mapping: std::collections::HashMap<String, Uuid>,
143143
) -> Result<(), Error> {
144144
let span = Span::current();
145145
span.pb_set_message("counting work");
@@ -150,8 +150,11 @@ pub async fn migrate(
150150
server_name,
151151
// We oversize the hashmaps, as the estimates are innaccurate, and we would like to avoid
152152
// reallocations.
153-
users: HashMap::with_capacity(counts.users * 9 / 8),
154-
devices_to_compat_sessions: HashMap::with_capacity(counts.devices * 9 / 8),
153+
users: HashMap::with_capacity_and_hasher(counts.users * 9 / 8, RandomState::default()),
154+
devices_to_compat_sessions: HashMap::with_capacity_and_hasher(
155+
counts.devices * 9 / 8,
156+
RandomState::default(),
157+
),
155158
provider_id_mapping,
156159
};
157160

0 commit comments

Comments
 (0)