From 0b4cb29386d34195d3030ce2cfb423866f39a775 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Fri, 9 Apr 2021 19:49:11 +0200 Subject: [PATCH] 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. --- core/gotham_state.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/gotham_state.rs b/core/gotham_state.rs index fa22878bba..b8f42137f5 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>, + data: BTreeMap>, } impl GothamState {