From 2be93a164f27f814c0611b79f8f39837c7bb087b Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 5 Feb 2024 14:25:21 +0100 Subject: [PATCH 1/2] lib: only build the ESM facade for builtins when they are needed We previously build the ESM facade (synthetic modules re-exporting builtin's exports) for builtins even when they are not directly import'ed (which rarely happens for internal builtins as that requires --expose-internals). This patch removes the eager generation to avoid the overhead and the extra promises created in facade building when it's not reqested by the user. When the facade is needed the ESM loader that can be requested it in the translator on-demand. Drive-by: set the ModuleWrap prototype to null in the built-in snapshot. --- lib/internal/bootstrap/realm.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/internal/bootstrap/realm.js b/lib/internal/bootstrap/realm.js index 0ebec1c02d0c0d..9cb6a8add714d0 100644 --- a/lib/internal/bootstrap/realm.js +++ b/lib/internal/bootstrap/realm.js @@ -198,6 +198,9 @@ const { setInternalLoaders, } = internalBinding('builtins'); +const { ModuleWrap } = internalBinding('module_wrap'); +ObjectSetPrototypeOf(ModuleWrap.prototype, null); + const getOwn = (target, property, receiver) => { return ObjectPrototypeHasOwnProperty(target, property) ? ReflectGet(target, property, receiver) : @@ -338,16 +341,11 @@ class BuiltinModule { const internal = StringPrototypeStartsWith(this.id, 'internal/'); this.exportKeys = internal ? [] : ObjectKeys(this.exports); } - this.getESMFacade(); - this.syncExports(); return this.exports; } getESMFacade() { if (this.module) return this.module; - const { ModuleWrap } = internalBinding('module_wrap'); - // TODO(aduh95): move this to C++, alongside the initialization of the class. - ObjectSetPrototypeOf(ModuleWrap.prototype, null); const url = `node:${this.id}`; const builtin = this; const exportsKeys = ArrayPrototypeSlice(this.exportKeys); From 397aadb3e1c2a919c282aa624c588f270c236418 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 5 Feb 2024 15:52:20 +0100 Subject: [PATCH 2/2] benchmark: rename startup.js to startup-core.js It is easier to filter the core startup benchmark with this name. --- .github/CODEOWNERS | 2 +- benchmark/misc/{startup.js => startup-core.js} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename benchmark/misc/{startup.js => startup-core.js} (100%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a79f7ab22af7e2..e4241de7d42e75 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -125,7 +125,7 @@ # Startup -/benchmark/misc/startup.js @nodejs/startup +/benchmark/misc/startup-* @nodejs/startup /lib/internal/bootstrap/* @nodejs/startup /src/node_builtins* @nodejs/startup /src/node_realm* @nodejs/startup @nodejs/realm diff --git a/benchmark/misc/startup.js b/benchmark/misc/startup-core.js similarity index 100% rename from benchmark/misc/startup.js rename to benchmark/misc/startup-core.js