From dca00211abf311de9fec4f73f8365e430787e3f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 10 Mar 2020 03:04:49 +0100 Subject: use Object instead of Map for promise table (#4309) --- cli/js/ops/dispatch_json.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'cli/js/ops/dispatch_json.ts') diff --git a/cli/js/ops/dispatch_json.ts b/cli/js/ops/dispatch_json.ts index 6fb9007df..4aa1f6b8b 100644 --- a/cli/js/ops/dispatch_json.ts +++ b/cli/js/ops/dispatch_json.ts @@ -19,7 +19,10 @@ interface JsonResponse { promiseId?: number; // Only present in async messages. } -const promiseTable = new Map>(); +// Using an object without a prototype because `Map` was causing GC problems. +const promiseTable: { + [key: number]: util.Resolvable; +} = Object.create(null); let _nextPromiseId = 1; function nextPromiseId(): number { @@ -48,9 +51,9 @@ export function asyncMsgFromRust(resUi8: Uint8Array): void { const res = decode(resUi8); util.assert(res.promiseId != null); - const promise = promiseTable.get(res.promiseId!); + const promise = promiseTable[res.promiseId!]; util.assert(promise != null); - promiseTable.delete(res.promiseId!); + delete promiseTable[res.promiseId!]; promise.resolve(res); } @@ -89,7 +92,7 @@ export async function sendAsync( promise.resolve(res); } else { // Async result. - promiseTable.set(promiseId, promise); + promiseTable[promiseId] = promise; } const res = await promise; -- cgit v1.2.3