From a9af072e2d2b5d0ddeb40a82c05bc4591a961596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 7 Mar 2023 11:11:54 -0400 Subject: [PATCH] perf: move runtime bootstrap code to snapshot time (#18062) This commit moves some of the code from "99_main.js" to be executed during the snapshot time instead of on each worker bootstrap. These should minimally help with startup time benchmark. --- runtime/js/99_main.js | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 0199c5148a..af24051be5 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -383,6 +383,8 @@ function promiseRejectMacrotaskCallback() { } let hasBootstrapped = false; +// Set up global properties shared by main and worker runtime. +ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope); function bootstrapMainRuntime(runtimeOptions) { if (hasBootstrapped) { @@ -392,12 +394,9 @@ function bootstrapMainRuntime(runtimeOptions) { performance.setTimeOrigin(DateNow()); globalThis_ = globalThis; - const consoleFromV8 = globalThis.Deno.core.console; - // Remove bootstrapping data from the global scope delete globalThis.__bootstrap; delete globalThis.bootstrap; - util.log("bootstrapMainRuntime"); hasBootstrapped = true; // If the `--location` flag isn't set, make `globalThis.location` `undefined` and @@ -411,7 +410,6 @@ function bootstrapMainRuntime(runtimeOptions) { location.setLocationHref(runtimeOptions.location); } - ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope); if (runtimeOptions.unstableFlag) { ObjectDefineProperties(globalThis, unstableWindowOrWorkerGlobalScope); } @@ -423,6 +421,7 @@ function bootstrapMainRuntime(runtimeOptions) { ObjectSetPrototypeOf(globalThis, Window.prototype); if (runtimeOptions.inspectFlag) { + const consoleFromV8 = core.console; const consoleFromDeno = globalThis.console; wrapConsole(consoleFromDeno, consoleFromV8); } @@ -529,9 +528,8 @@ function bootstrapWorkerRuntime( // Remove bootstrapping data from the global scope delete globalThis.__bootstrap; delete globalThis.bootstrap; - util.log("bootstrapWorkerRuntime"); hasBootstrapped = true; - ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope); + if (runtimeOptions.unstableFlag) { ObjectDefineProperties(globalThis, unstableWindowOrWorkerGlobalScope); } @@ -634,12 +632,7 @@ function bootstrapWorkerRuntime( ObjectDefineProperty(globalThis, "Deno", util.readOnly(finalDenoNs)); } -ObjectDefineProperties(globalThis, { - bootstrap: { - value: { - mainRuntime: bootstrapMainRuntime, - workerRuntime: bootstrapWorkerRuntime, - }, - configurable: true, - }, -}); +globalThis.bootstrap = { + mainRuntime: bootstrapMainRuntime, + workerRuntime: bootstrapWorkerRuntime, +};