diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-10-14 23:46:27 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-10-14 17:46:27 -0400 |
commit | 4221b90c3febbe03a4b47e47248263741a0fdd4a (patch) | |
tree | 0c16487c197863fb1223f37a9c589905517dfdcd /cli/js | |
parent | 605659535794ca0d8fe3ee4ea5857b418d7ce091 (diff) |
perf: eager poll async ops in Isolate (#3046)
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/dispatch_json.ts | 12 | ||||
-rw-r--r-- | cli/js/dispatch_minimal.ts | 16 |
2 files changed, 23 insertions, 5 deletions
diff --git a/cli/js/dispatch_json.ts b/cli/js/dispatch_json.ts index 572ec855a..890568409 100644 --- a/cli/js/dispatch_json.ts +++ b/cli/js/dispatch_json.ts @@ -75,11 +75,17 @@ export async function sendAsync( const promiseId = nextPromiseId(); args = Object.assign(args, { promiseId }); const promise = util.createResolvable<Ok>(); - promiseTable.set(promiseId, promise); const argsUi8 = encode(args); - const resUi8 = core.dispatch(opId, argsUi8, zeroCopy); - util.assert(resUi8 == null); + const buf = core.dispatch(opId, argsUi8, zeroCopy); + if (buf) { + // Sync result. + const res = decode(buf); + promise.resolve(res); + } else { + // Async result. + promiseTable.set(promiseId, promise); + } const res = await promise; return unwrapResponse(res); diff --git a/cli/js/dispatch_minimal.ts b/cli/js/dispatch_minimal.ts index 98636f85b..74a5e211c 100644 --- a/cli/js/dispatch_minimal.ts +++ b/cli/js/dispatch_minimal.ts @@ -61,8 +61,20 @@ export function sendAsyncMinimal( scratch32[1] = arg; scratch32[2] = 0; // result const promise = util.createResolvable<number>(); - promiseTableMin.set(promiseId, promise); - core.dispatch(opId, scratchBytes, zeroCopy); + const buf = core.dispatch(opId, scratchBytes, zeroCopy); + if (buf) { + const buf32 = new Int32Array( + buf.buffer, + buf.byteOffset, + buf.byteLength / 4 + ); + const record = recordFromBufMinimal(opId, buf32); + // Sync result. + promise.resolve(record.result); + } else { + // Async result. + promiseTableMin.set(promiseId, promise); + } return promise; } |