From 83e9ea091205b761abc23677637bc51e457e4662 Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Wed, 10 Jan 2024 10:05:13 +0000 Subject: [PATCH 1/2] Bump version to 2.14.5 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index 386fbe425a..81b35e2a6e 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "2.14.4", + "version": "2.14.5", "npmClient": "yarn", "packages": [ "packages/*", From 19bd2726b3b3e9e25fbdd78a8d25e8c05679ec77 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 10 Jan 2024 10:07:41 +0000 Subject: [PATCH 2/2] Move traces around in runJS to further pinpoint where time is spent. --- packages/server/src/jsRunner.ts | 72 ++++++++++++++++----------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/packages/server/src/jsRunner.ts b/packages/server/src/jsRunner.ts index 6fde3ab82a..9594ffaf65 100644 --- a/packages/server/src/jsRunner.ts +++ b/packages/server/src/jsRunner.ts @@ -12,51 +12,49 @@ export function init() { const perRequestLimit = env.JS_PER_REQUEST_TIME_LIMIT_MS let track: TrackerFn = f => f() if (perRequestLimit) { - tracer.trace("runJS.setupTracker", {}, span => { - const bbCtx = context.getCurrentContext() - if (bbCtx) { - if (!bbCtx.jsExecutionTracker) { - span?.addTags({ - createdExecutionTracker: true, - }) - bbCtx.jsExecutionTracker = - timers.ExecutionTimeTracker.withLimit(perRequestLimit) - } + const bbCtx = tracer.trace("runJS.getCurrentContext", {}, span => + context.getCurrentContext() + ) + if (bbCtx) { + if (!bbCtx.jsExecutionTracker) { span?.addTags({ - js: { - limitMS: bbCtx.jsExecutionTracker.limitMs, - elapsedMS: bbCtx.jsExecutionTracker.elapsedMS, - }, + createdExecutionTracker: true, }) - // We call checkLimit() here to prevent paying the cost of creating - // a new VM context below when we don't need to. - bbCtx.jsExecutionTracker.checkLimit() - track = bbCtx.jsExecutionTracker.track.bind( - bbCtx.jsExecutionTracker + bbCtx.jsExecutionTracker = tracer.trace( + "runJS.createExecutionTimeTracker", + {}, + span => timers.ExecutionTimeTracker.withLimit(perRequestLimit) ) } - }) + span?.addTags({ + js: { + limitMS: bbCtx.jsExecutionTracker.limitMs, + elapsedMS: bbCtx.jsExecutionTracker.elapsedMS, + }, + }) + // We call checkLimit() here to prevent paying the cost of creating + // a new VM context below when we don't need to. + tracer.trace("runJS.checkLimitAndBind", {}, span => { + bbCtx.jsExecutionTracker!.checkLimit() + track = bbCtx.jsExecutionTracker!.track.bind( + bbCtx.jsExecutionTracker + ) + }) + } } - ctx = tracer.trace("runJS.ctxClone", {}, span => { - return { - ...ctx, - alert: undefined, - setInterval: undefined, - setTimeout: undefined, - } - }) - - tracer.trace("runJS.vm.createContext", {}, span => { - vm.createContext(ctx) - }) + ctx = { + ...ctx, + alert: undefined, + setInterval: undefined, + setTimeout: undefined, + } + vm.createContext(ctx) return track(() => - tracer.trace("runJS.vm.runInNewContext", {}, span => - vm.runInNewContext(js, ctx, { - timeout: env.JS_PER_EXECUTION_TIME_LIMIT_MS, - }) - ) + vm.runInNewContext(js, ctx, { + timeout: env.JS_PER_EXECUTION_TIME_LIMIT_MS, + }) ) }) })