From 30628288ce2b411ca3def46129a4606073e16bac Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 1 May 2023 14:21:27 -0400 Subject: perf: lazily retrieve ppid (#18940) This is very apparent on Windows. Before: 45.74ms (Hello world) After: 33.92ms Closes #18939 --- runtime/js/99_main.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'runtime/js') diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 854a0029e..f0c63df74 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -427,12 +427,11 @@ function bootstrapMainRuntime(runtimeOptions) { 8: tsVersion, 9: unstableFlag, 10: pid, - 11: ppid, - 12: target, - 13: v8Version, - 14: userAgent, - 15: inspectFlag, - // 16: enableTestingFeaturesFlag + 11: target, + 12: v8Version, + 13: userAgent, + 14: inspectFlag, + // 15: enableTestingFeaturesFlag } = runtimeOptions; performance.setTimeOrigin(DateNow()); @@ -495,9 +494,16 @@ function bootstrapMainRuntime(runtimeOptions) { setUserAgent(userAgent); setLanguage(locale); + let ppid = undefined; ObjectDefineProperties(finalDenoNs, { pid: util.readOnly(pid), - ppid: util.readOnly(ppid), + ppid: util.getterOnly(() => { + // lazy because it's expensive + if (ppid === undefined) { + ppid = ops.op_ppid(); + } + return ppid; + }), noColor: util.readOnly(noColor), args: util.readOnly(ObjectFreeze(args)), mainModule: util.getterOnly(opMainModule), @@ -535,12 +541,11 @@ function bootstrapWorkerRuntime( 8: tsVersion, 9: unstableFlag, 10: pid, - // 11: ppid, - 12: target, - 13: v8Version, - // 14: userAgent, - // 15: inspectFlag, - 16: enableTestingFeaturesFlag, + 11: target, + 12: v8Version, + // 13: userAgent, + // 14: inspectFlag, + 15: enableTestingFeaturesFlag, } = runtimeOptions; performance.setTimeOrigin(DateNow()); -- cgit v1.2.3