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` |
This commit is contained in:
Divy Srivastava 2023-03-31 21:28:21 +05:30 committed by GitHub
parent feab94ff51
commit aa9b94a80e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 18 deletions

View file

@ -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,