Skip to content

Commit

Permalink
perf: move setting up Deno namespace to snapshot time (denoland#18067)
Browse files Browse the repository at this point in the history
No need to do it on startup every time.
  • Loading branch information
bartlomieju committed Mar 8, 2023
1 parent b32a6f8 commit 9eb987e
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,20 @@ function promiseRejectMacrotaskCallback() {
let hasBootstrapped = false;
// Set up global properties shared by main and worker runtime.
ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope);
// FIXME(bartlomieju): temporarily add whole `Deno.core` to
// `Deno[Deno.internal]` namespace. It should be removed and only necessary
// methods should be left there.
ObjectAssign(internals, {
core,
});
const internalSymbol = Symbol("Deno.internal");
const finalDenoNs = {
internal: internalSymbol,
[internalSymbol]: internals,
resources: core.resources,
close: core.close,
...denoNs,
};

function bootstrapMainRuntime(runtimeOptions) {
if (hasBootstrapped) {
Expand Down Expand Up @@ -452,8 +466,6 @@ function bootstrapMainRuntime(runtimeOptions) {
setUserAgent(runtimeOptions.userAgent);
setLanguage(runtimeOptions.locale);

const internalSymbol = Symbol("Deno.internal");

// These have to initialized here and not in `90_deno_ns.js` because
// the op function that needs to be passed will be invalidated by creating
// a snapshot
Expand All @@ -475,13 +487,6 @@ function bootstrapMainRuntime(runtimeOptions) {
core,
});

const finalDenoNs = {
internal: internalSymbol,
[internalSymbol]: internals,
resources: core.resources,
close: core.close,
...denoNs,
};
ObjectDefineProperties(finalDenoNs, {
pid: util.readOnly(runtimeOptions.pid),
ppid: util.readOnly(runtimeOptions.ppid),
Expand Down Expand Up @@ -579,8 +584,6 @@ function bootstrapWorkerRuntime(

globalThis.pollForMessages = pollForMessages;

const internalSymbol = Symbol("Deno.internal");

// These have to initialized here and not in `90_deno_ns.js` because
// the op function that needs to be passed will be invalidated by creating
// a snapshot
Expand All @@ -602,13 +605,6 @@ function bootstrapWorkerRuntime(
core,
});

const finalDenoNs = {
internal: internalSymbol,
[internalSymbol]: internals,
resources: core.resources,
close: core.close,
...denoNs,
};
if (runtimeOptions.unstableFlag) {
ObjectAssign(finalDenoNs, denoNsUnstable);
// These have to initialized here and not in `90_deno_ns.js` because
Expand Down

0 comments on commit 9eb987e

Please sign in to comment.