summaryrefslogtreecommitdiff
path: root/js/dispatch_minimal.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-06-14 13:58:20 -0400
committerRyan Dahl <ry@tinyclouds.org>2019-06-14 13:56:36 -0700
commit1361e302234b17ab8079107b134dfd0ddf288439 (patch)
treea38ce903ddbd89ee2dfd437bd8f984cb1d85695b /js/dispatch_minimal.ts
parent3dff147d0ca1a2cd8d264d20a178d71cb38b1c4e (diff)
Revert "Refactor dispatch handling (#2452)"
Due to performance regression: https://github.com/denoland/deno/commit/dc60fe9f300043f191286ef804a365e16e455f87#commitcomment-33943711 This reverts commit dc60fe9f300043f191286ef804a365e16e455f87.
Diffstat (limited to 'js/dispatch_minimal.ts')
-rw-r--r--js/dispatch_minimal.ts30
1 files changed, 18 insertions, 12 deletions
diff --git a/js/dispatch_minimal.ts b/js/dispatch_minimal.ts
index bf9065f56..17d328110 100644
--- a/js/dispatch_minimal.ts
+++ b/js/dispatch_minimal.ts
@@ -5,8 +5,14 @@ import { core } from "./core";
const DISPATCH_MINIMAL_TOKEN = 0xcafe;
const promiseTableMin = new Map<number, util.Resolvable<number>>();
+let _nextPromiseId = 0;
+
+export function nextPromiseId(): number {
+ return _nextPromiseId++;
+}
export interface RecordMinimal {
+ promiseId: number;
opId: number;
arg: number;
result: number;
@@ -22,9 +28,10 @@ export function hasMinimalToken(i32: Int32Array): boolean {
export function recordFromBufMinimal(buf32: Int32Array): null | RecordMinimal {
if (hasMinimalToken(buf32)) {
return {
- opId: buf32[1],
- arg: buf32[2],
- result: buf32[3]
+ promiseId: buf32[1],
+ opId: buf32[2],
+ arg: buf32[3],
+ result: buf32[4]
};
}
return null;
@@ -39,13 +46,12 @@ const scratchBytes = new Uint8Array(
util.assert(scratchBytes.byteLength === scratch32.length * 4);
export function handleAsyncMsgFromRustMinimal(
- promiseId: number,
ui8: Uint8Array,
record: RecordMinimal
): void {
// Fast and new
util.log("minimal handleAsyncMsgFromRust ", ui8.length);
- const { result } = record;
+ const { promiseId, result } = record;
const promise = promiseTableMin.get(promiseId);
promiseTableMin.delete(promiseId);
promise!.resolve(result);
@@ -56,16 +62,16 @@ export function sendAsyncMinimal(
arg: number,
zeroCopy: Uint8Array
): Promise<number> {
- scratch32[0] = DISPATCH_MINIMAL_TOKEN;
- scratch32[1] = opId;
- scratch32[2] = arg;
+ const promiseId = nextPromiseId(); // AKA cmdId
- const promiseId = core.dispatch(scratchBytes, zeroCopy);
-
- util.assert(typeof promiseId == "number");
+ scratch32[0] = DISPATCH_MINIMAL_TOKEN;
+ scratch32[1] = promiseId;
+ scratch32[2] = opId;
+ scratch32[3] = arg;
const promise = util.createResolvable<number>();
- promiseTableMin.set(promiseId as number, promise);
+ promiseTableMin.set(promiseId, promise);
+ core.dispatch(scratchBytes, zeroCopy);
return promise;
}