diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-03-10 03:04:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-09 22:04:49 -0400 |
commit | dca00211abf311de9fec4f73f8365e430787e3f9 (patch) | |
tree | 594fc4cb7fb0a3bc9dba0af69a1b37b4d7f087d5 /cli/js/ops/dispatch_minimal.ts | |
parent | 68119e1d7ed23421ccdcba20532ebe9ae3df9f18 (diff) |
use Object instead of Map for promise table (#4309)
Diffstat (limited to 'cli/js/ops/dispatch_minimal.ts')
-rw-r--r-- | cli/js/ops/dispatch_minimal.ts | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/cli/js/ops/dispatch_minimal.ts b/cli/js/ops/dispatch_minimal.ts index 7aec4683c..61d630240 100644 --- a/cli/js/ops/dispatch_minimal.ts +++ b/cli/js/ops/dispatch_minimal.ts @@ -4,7 +4,11 @@ import { core } from "../core.ts"; import { TextDecoder } from "../web/text_encoding.ts"; import { ErrorKind, errors, getErrorClass } from "../errors.ts"; -const promiseTableMin = new Map<number, util.Resolvable<RecordMinimal>>(); +// Using an object without a prototype because `Map` was causing GC problems. +const promiseTableMin: { + [key: number]: util.Resolvable<RecordMinimal>; +} = Object.create(null); + // Note it's important that promiseId starts at 1 instead of 0, because sync // messages are indicated with promiseId 0. If we ever add wrap around logic for // overflows, this should be taken into account. @@ -72,8 +76,8 @@ util.assert(scratchBytes.byteLength === scratch32.length * 4); export function asyncMsgFromRust(ui8: Uint8Array): void { const record = recordFromBufMinimal(ui8); const { promiseId } = record; - const promise = promiseTableMin.get(promiseId); - promiseTableMin.delete(promiseId); + const promise = promiseTableMin[promiseId]; + delete promiseTableMin[promiseId]; util.assert(promise); promise.resolve(record); } @@ -95,7 +99,7 @@ export async function sendAsyncMinimal( promise.resolve(record); } else { // Async result. - promiseTableMin.set(promiseId, promise); + promiseTableMin[promiseId] = promise; } const res = await promise; |