Skip to content

⚡ Bolt: Optimize HashMap hasher for room lookups#741

Open
kevinaboos wants to merge 1 commit intomainfrom
bolt-optimize-hashmaps-16200498334128599928
Open

⚡ Bolt: Optimize HashMap hasher for room lookups#741
kevinaboos wants to merge 1 commit intomainfrom
bolt-optimize-hashmaps-16200498334128599928

Conversation

@kevinaboos
Copy link
Member

💡 What: Replaced SipHash (via std::collections::hash_map::DefaultHasher) with AHash (default in hashbrown) for critical static HashMaps (ALL_JOINED_ROOMS and IGNORED_USERS).
🎯 Why: SipHash is cryptographically secure but slower. AHash is significantly faster and sufficient for internal HashMap usage, especially with frequent lookups in the application's hot path.
📊 Impact: Faster room lookups and set membership checks. ALL_JOINED_ROOMS is accessed on every matrix request.
🔬 Measurement: Verified with cargo check and cargo test. The change is internal refactoring of static initialization using LazyLock.


PR created automatically by Jules for task 16200498334128599928 started by @kevinaboos

Replaced `BuildHasherDefault<DefaultHasher>` (SipHash) with `hashbrown`'s default hasher (AHash) for `ALL_JOINED_ROOMS` and `IGNORED_USERS`. This is achieved by initializing these static collections using `std::sync::LazyLock` instead of `const` initialization, which enables using the faster, non-const-constructible AHash.

This optimization improves performance for frequent HashMap lookups, particularly in the `matrix_worker_task` loop.

Also updated `get_ignored_users` return type and removed unused imports.

Co-authored-by: kevinaboos <1139460+kevinaboos@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant