0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-29 08:58:01 -04:00

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.
This commit is contained in:
Aaron O'Mullan 2021-04-09 19:49:11 +02:00 committed by GitHub
parent c86ee742a2
commit 0b4cb29386
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 {