1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -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 GitHub
parent 08591d052a
commit 76d085ff6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,
};