1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-07 06:46:59 -05:00

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.
This commit is contained in:
Bartek Iwańczuk 2023-03-07 11:11:54 -04:00 committed by Yoshiya Hinosawa
parent 36fc29869a
commit a9af072e2d

View file

@ -383,6 +383,8 @@ function promiseRejectMacrotaskCallback() {
} }
let hasBootstrapped = false; let hasBootstrapped = false;
// Set up global properties shared by main and worker runtime.
ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope);
function bootstrapMainRuntime(runtimeOptions) { function bootstrapMainRuntime(runtimeOptions) {
if (hasBootstrapped) { if (hasBootstrapped) {
@ -392,12 +394,9 @@ function bootstrapMainRuntime(runtimeOptions) {
performance.setTimeOrigin(DateNow()); performance.setTimeOrigin(DateNow());
globalThis_ = globalThis; globalThis_ = globalThis;
const consoleFromV8 = globalThis.Deno.core.console;
// Remove bootstrapping data from the global scope // Remove bootstrapping data from the global scope
delete globalThis.__bootstrap; delete globalThis.__bootstrap;
delete globalThis.bootstrap; delete globalThis.bootstrap;
util.log("bootstrapMainRuntime");
hasBootstrapped = true; hasBootstrapped = true;
// If the `--location` flag isn't set, make `globalThis.location` `undefined` and // If the `--location` flag isn't set, make `globalThis.location` `undefined` and
@ -411,7 +410,6 @@ function bootstrapMainRuntime(runtimeOptions) {
location.setLocationHref(runtimeOptions.location); location.setLocationHref(runtimeOptions.location);
} }
ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope);
if (runtimeOptions.unstableFlag) { if (runtimeOptions.unstableFlag) {
ObjectDefineProperties(globalThis, unstableWindowOrWorkerGlobalScope); ObjectDefineProperties(globalThis, unstableWindowOrWorkerGlobalScope);
} }
@ -423,6 +421,7 @@ function bootstrapMainRuntime(runtimeOptions) {
ObjectSetPrototypeOf(globalThis, Window.prototype); ObjectSetPrototypeOf(globalThis, Window.prototype);
if (runtimeOptions.inspectFlag) { if (runtimeOptions.inspectFlag) {
const consoleFromV8 = core.console;
const consoleFromDeno = globalThis.console; const consoleFromDeno = globalThis.console;
wrapConsole(consoleFromDeno, consoleFromV8); wrapConsole(consoleFromDeno, consoleFromV8);
} }
@ -529,9 +528,8 @@ function bootstrapWorkerRuntime(
// Remove bootstrapping data from the global scope // Remove bootstrapping data from the global scope
delete globalThis.__bootstrap; delete globalThis.__bootstrap;
delete globalThis.bootstrap; delete globalThis.bootstrap;
util.log("bootstrapWorkerRuntime");
hasBootstrapped = true; hasBootstrapped = true;
ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope);
if (runtimeOptions.unstableFlag) { if (runtimeOptions.unstableFlag) {
ObjectDefineProperties(globalThis, unstableWindowOrWorkerGlobalScope); ObjectDefineProperties(globalThis, unstableWindowOrWorkerGlobalScope);
} }
@ -634,12 +632,7 @@ function bootstrapWorkerRuntime(
ObjectDefineProperty(globalThis, "Deno", util.readOnly(finalDenoNs)); ObjectDefineProperty(globalThis, "Deno", util.readOnly(finalDenoNs));
} }
ObjectDefineProperties(globalThis, { globalThis.bootstrap = {
bootstrap: { mainRuntime: bootstrapMainRuntime,
value: { workerRuntime: bootstrapWorkerRuntime,
mainRuntime: bootstrapMainRuntime, };
workerRuntime: bootstrapWorkerRuntime,
},
configurable: true,
},
});