From ecbd5149f87208a27bd9ec6cfef708967d8e784a Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Wed, 31 Jan 2024 20:30:18 +0100 Subject: [PATCH] Use faster hash map for thread results --- Cargo.lock | 1 + Cargo.toml | 1 + lib/result_map.rs | 18 +++++++++--------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9db513f..154ab27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -338,6 +338,7 @@ dependencies = [ "event-listener", "futures-lite", "mlua", + "rustc-hash", "tracing", "tracing-subscriber", ] diff --git a/Cargo.toml b/Cargo.toml index d954505..ae7b873 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ concurrent-queue = "2.4" derive_more = "0.99" event-listener = "4.0" futures-lite = "2.2" +rustc-hash = "1.1" tracing = "0.1" mlua = { version = "0.9.5", features = [ diff --git a/lib/result_map.rs b/lib/result_map.rs index 7295f42..4d406ff 100644 --- a/lib/result_map.rs +++ b/lib/result_map.rs @@ -1,24 +1,24 @@ #![allow(clippy::inline_always)] -use std::{ - cell::RefCell, - collections::{HashMap, HashSet}, - rc::Rc, -}; +use std::{cell::RefCell, rc::Rc}; + +// NOTE: This is the hash algorithm that mlua also uses, so we +// are not adding any additional dependencies / bloat by using it. +use rustc_hash::{FxHashMap, FxHashSet}; use crate::{thread_id::ThreadId, util::ThreadResult}; #[derive(Clone)] pub(crate) struct ThreadResultMap { - tracked: Rc>>, - inner: Rc>>, + tracked: Rc>>, + inner: Rc>>, } impl ThreadResultMap { pub fn new() -> Self { Self { - tracked: Rc::new(RefCell::new(HashSet::new())), - inner: Rc::new(RefCell::new(HashMap::new())), + tracked: Rc::new(RefCell::new(FxHashSet::default())), + inner: Rc::new(RefCell::new(FxHashMap::default())), } }