From 4e8edafb398f52499f9e975ffb8765cdbd268f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 8 Mar 2023 23:42:46 -0400 Subject: perf(core): over-allocate in ModuleMap when running from snapshot (#18083) This commit changes "ModuleMap" initialization to over-allocate by 16 for vectors storing module information and module V8 handles. In 99% cases there's gonna be at least one additional module loaded, so it's very wasteful to have to reallocate when the module is executed (IIRC Rust will double the size of the vector) and move all of the elements. --- core/modules.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'core/modules.rs') diff --git a/core/modules.rs b/core/modules.rs index 3a3b1c370..ee5f72d9d 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -1129,7 +1129,8 @@ impl ModuleMap { let info_arr: v8::Local = info_val.try_into().unwrap(); let len = info_arr.length() as usize; - let mut info = Vec::with_capacity(len); + // Over allocate so executing a few scripts doesn't have to resize this vec. + let mut info = Vec::with_capacity(len + 16); for i in 0..len { let module_info_arr: v8::Local = info_arr -- cgit v1.2.3