From 85aeaff891283e4714de7f7a39eb2d78ff86aaff Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 14 Feb 2024 12:52:20 +0100 Subject: [PATCH] Shave time on release --- packages/server/src/jsRunner/vm/index.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/server/src/jsRunner/vm/index.ts b/packages/server/src/jsRunner/vm/index.ts index e8eedd9c68..0285af8620 100644 --- a/packages/server/src/jsRunner/vm/index.ts +++ b/packages/server/src/jsRunner/vm/index.ts @@ -84,7 +84,11 @@ export class IsolatedVM implements VM { const script = this.isolate.compileScriptSync( `${injectedRequire};${helpersSource};helpers=helpers.default` ) - script.runSync(this.vm, { timeout: this.invocationTimeout, release: true }) + + script.runSync(this.vm, { timeout: this.invocationTimeout, release: false }) + new Promise(() => { + script.release() + }) return this } @@ -150,7 +154,10 @@ export class IsolatedVM implements VM { const script = this.isolate.compileScriptSync( `${textDecoderPolyfill};${bsonSource}` ) - script.runSync(this.vm, { timeout: this.invocationTimeout, release: true }) + script.runSync(this.vm, { timeout: this.invocationTimeout, release: false }) + new Promise(() => { + script.release() + }) return this } @@ -169,7 +176,10 @@ export class IsolatedVM implements VM { const script = this.isolate.compileScriptSync(code) - script.runSync(this.vm, { timeout: this.invocationTimeout, release: true }) + script.runSync(this.vm, { timeout: this.invocationTimeout, release: false }) + new Promise(() => { + script.release() + }) // We can't rely on the script run result as it will not work for non-transferable values const result = this.getFromContext(this.resultKey) @@ -213,7 +223,10 @@ export class IsolatedVM implements VM { private getFromContext(key: string) { const ref = this.vm.global.getSync(key, { reference: true }) const result = ref.copySync() - ref.release() + + new Promise(() => { + ref.release() + }) return result } }