Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Use faster hash map for thread results
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Jan 31, 2024
1 parent a5d411e commit ecbd514
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
18 changes: 9 additions & 9 deletions lib/result_map.rs
Original file line number Diff line number Diff line change
@@ -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<RefCell<HashSet<ThreadId>>>,
inner: Rc<RefCell<HashMap<ThreadId, ThreadResult>>>,
tracked: Rc<RefCell<FxHashSet<ThreadId>>>,
inner: Rc<RefCell<FxHashMap<ThreadId, ThreadResult>>>,
}

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())),
}
}

Expand Down

0 comments on commit ecbd514

Please sign in to comment.