From 4b6305f4f25fc76f974bbdcc9cdb139d5ab8f5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 18 Mar 2023 07:51:21 -0400 Subject: perf(core): preserve ops between snapshots (#18080) This commit changes the build process in a way that preserves already registered ops in the snapshot. This allows us to skip creating hundreds of "v8::String" on each startup, but sadly there is still some op registration going on startup (however we're registering 49 ops instead of >200 ops). This situation could be further improved, by moving some of the ops from "runtime/" to a separate extension crates. --------- Co-authored-by: Divy Srivastava --- core/extensions.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'core/extensions.rs') diff --git a/core/extensions.rs b/core/extensions.rs index bba37ca3e..801f5f1a6 100644 --- a/core/extensions.rs +++ b/core/extensions.rs @@ -53,6 +53,7 @@ pub struct OpDecl { pub is_unstable: bool, pub is_v8: bool, pub fast_fn: Option>, + pub force_registration: bool, } impl OpDecl { @@ -240,6 +241,7 @@ macro_rules! extension { #[inline(always)] #[allow(unused_variables)] + #[allow(clippy::redundant_closure_call)] fn with_customizer(ext: &mut $crate::ExtensionBuilder) { $( ($customizer_fn)(ext); )? } @@ -325,6 +327,7 @@ pub struct Extension { enabled: bool, name: &'static str, deps: Option<&'static [&'static str]>, + force_op_registration: bool, } // Note: this used to be a trait, but we "downgraded" it to a single concrete type @@ -394,6 +397,7 @@ impl Extension { let mut ops = self.ops.take()?; for op in ops.iter_mut() { op.enabled = self.enabled && op.enabled; + op.force_registration = self.force_op_registration; } Some(ops) } @@ -447,6 +451,7 @@ pub struct ExtensionBuilder { event_loop_middleware: Option>, name: &'static str, deps: &'static [&'static str], + force_op_registration: bool, } impl ExtensionBuilder { @@ -511,6 +516,15 @@ impl ExtensionBuilder { self } + /// Mark that ops from this extension should be added to `Deno.core.ops` + /// unconditionally. This is useful is some ops are not available + /// during snapshotting, as ops are not registered by default when a + /// `JsRuntime` is created with an existing snapshot. + pub fn force_op_registration(&mut self) -> &mut Self { + self.force_op_registration = true; + self + } + /// Consume the [`ExtensionBuilder`] and return an [`Extension`]. pub fn take(self) -> Extension { let js_files = Some(self.js); @@ -528,6 +542,7 @@ impl ExtensionBuilder { initialized: false, enabled: true, name: self.name, + force_op_registration: self.force_op_registration, deps, } } @@ -549,6 +564,7 @@ impl ExtensionBuilder { enabled: true, name: self.name, deps, + force_op_registration: self.force_op_registration, } } } -- cgit v1.2.3