summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-04-09 19:49:11 +0200
committerGitHub <noreply@github.com>2021-04-09 19:49:11 +0200
commit0b4cb29386d34195d3030ce2cfb423866f39a775 (patch)
treefcb703e363dece1a39a9b86aea8d672df1a8fd16
parentc86ee742a2522a169bfe40890b946c646aeac1cf (diff)
perf(core): use BTreeMap for GothamState (#10073)
This commit replaces GothamState's internal HashMap with a BTreeMap to improve performance. OpState/GothamState keys by TypeId which is essentially an opaque u64. For small sets of integer keys BTreeMap outperforms HashMap mainly since it removes the hashing overhead and Eq/Comp on integer-like types is very cheap, it should also have a smaller memory footprint. We only use ~30 unique types and thus ~30 unique keys to access OpState, so the keyset is small and immutable throughout the life of a JsRuntime, there's no meaningful churn in keys added/removed.
-rw-r--r--core/gotham_state.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/core/gotham_state.rs b/core/gotham_state.rs
index fa22878bb..b8f42137f 100644
--- a/core/gotham_state.rs
+++ b/core/gotham_state.rs
@@ -6,11 +6,11 @@
use log::trace;
use std::any::Any;
use std::any::TypeId;
-use std::collections::HashMap;
+use std::collections::BTreeMap;
#[derive(Default)]
pub struct GothamState {
- data: HashMap<TypeId, Box<dyn Any>>,
+ data: BTreeMap<TypeId, Box<dyn Any>>,
}
impl GothamState {