diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-03-31 21:28:21 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-31 21:28:21 +0530 |
commit | aa9b94a80eadde7737417eb7d412559bc567c77c (patch) | |
tree | 14691957c663ad9d6c18ce837823f46e4ddc4347 /core | |
parent | feab94ff512987a9a7e01f41d7a1788712b4247c (diff) |
perf(ext/websocket): use opAsync2 to avoid spread deopt (#18525)
This commit adds a new core API `opAsync2` to call an async op with
atmost 2 arguments. Spread argument iterators has a pretty big perf hit
when calling ops.
| name | avg msg/sec/core |
| --- | --- |
| 1.32.1 | `127820.750000` |
| #18506 | `140079.000000` |
| #18506 + #18509 | `150104.250000` |
| #18506 + #18509 + this | `157340.000000` |
Diffstat (limited to 'core')
-rw-r--r-- | core/01_core.js | 19 | ||||
-rw-r--r-- | core/examples/http_bench_json_ops/http_bench_json_ops.js | 4 | ||||
-rw-r--r-- | core/runtime.rs | 2 |
3 files changed, 19 insertions, 6 deletions
diff --git a/core/01_core.js b/core/01_core.js index a13bdc8dd..c46c30070 100644 --- a/core/01_core.js +++ b/core/01_core.js @@ -191,12 +191,24 @@ return res; } - function rollPromiseId() { - return nextPromiseId++; + function opAsync2(name, arg0, arg1) { + const id = nextPromiseId++; + let promise = PromisePrototypeThen(setPromise(id), unwrapOpResult); + try { + ops[name](id, arg0, arg1); + } catch (err) { + // Cleanup the just-created promise + getPromise(id); + // Rethrow the error + throw err; + } + promise = handleOpCallTracing(name, id, promise); + promise[promiseIdSymbol] = id; + return promise; } function opAsync(name, ...args) { - const id = rollPromiseId(); + const id = nextPromiseId++; let promise = PromisePrototypeThen(setPromise(id), unwrapOpResult); try { ops[name](id, ...new SafeArrayIterator(args)); @@ -376,6 +388,7 @@ // Extra Deno.core.* exports const core = ObjectAssign(globalThis.Deno.core, { opAsync, + opAsync2, resources, metrics, registerErrorBuilder, diff --git a/core/examples/http_bench_json_ops/http_bench_json_ops.js b/core/examples/http_bench_json_ops/http_bench_json_ops.js index 5a205188b..0c3b5be13 100644 --- a/core/examples/http_bench_json_ops/http_bench_json_ops.js +++ b/core/examples/http_bench_json_ops/http_bench_json_ops.js @@ -3,7 +3,7 @@ // then write this fixed 'responseBuf'. The point of this benchmark is to // exercise the event loop in a simple yet semi-realistic way. -const { ops, opAsync } = Deno.core; +const { ops, opAsync, opAsync2 } = Deno.core; const requestBuf = new Uint8Array(64 * 1024); const responseBuf = new Uint8Array( @@ -23,7 +23,7 @@ function accept(serverRid) { } function read(serverRid, buf) { - return opAsync("op_read_socket", serverRid, buf); + return opAsync2("op_read_socket", serverRid, buf); } async function serve(rid) { diff --git a/core/runtime.rs b/core/runtime.rs index bfb4c45cc..d68cb3616 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -2918,7 +2918,7 @@ pub mod tests { r#" let zero_copy_a = new Uint8Array([0]); - Deno.core.opAsync("op_test", null, zero_copy_a); + Deno.core.opAsync2("op_test", null, zero_copy_a); "#, ) .unwrap(); |