diff options
author | Aapo Alasuutari <aapo.alasuutari@gmail.com> | 2022-08-11 16:56:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-11 15:56:56 +0200 |
commit | 2164f6b1eb7216c1045d547c94f26fe3ceaa9403 (patch) | |
tree | 056e3d6540ebd0e755650765adcff6b5cc173db8 /runtime/js/99_main.js | |
parent | 883269f1f183428f60c54223135d8dd25977b3cd (diff) |
perf(ops): Monomorphic sync op calls (#15337)
Welcome to better optimised op calls! Currently opSync is called with parameters of every type and count. This most definitely makes the call megamorphic. Additionally, it seems that spread params leads to V8 not being able to optimise the calls quite as well (apparently Fast Calls cannot be used with spread params).
Monomorphising op calls should lead to some improved performance. Now that unwrapping of sync ops results is done on Rust side, this is pretty simple:
```
opSync("op_foo", param1, param2);
// -> turns to
ops.op_foo(param1, param2);
```
This means sync op calls are now just directly calling the native binding function. When V8 Fast API Calls are enabled, this will enable those to be called on the optimised path.
Monomorphising async ops likely requires using callbacks and is left as an exercise to the reader.
Diffstat (limited to 'runtime/js/99_main.js')
-rw-r--r-- | runtime/js/99_main.js | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index b397fcb47..cbc5c1b5b 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -10,6 +10,7 @@ delete Intl.v8BreakIterator; ((window) => { const core = Deno.core; + const ops = core.ops; const { ArrayPrototypeIndexOf, ArrayPrototypePush, @@ -103,7 +104,7 @@ delete Intl.v8BreakIterator; } isClosing = true; - core.opSync("op_worker_close"); + ops.op_worker_close(); } function postMessage(message, transferOrOptions = {}) { @@ -133,7 +134,7 @@ delete Intl.v8BreakIterator; } const { transfer } = options; const data = serializeJsMessageData(message, transfer); - core.opSync("op_worker_post_message", data); + ops.op_worker_post_message(data); } let isClosing = false; @@ -184,7 +185,7 @@ delete Intl.v8BreakIterator; let loadedMainWorkerScript = false; function importScripts(...urls) { - if (core.opSync("op_worker_get_type") === "module") { + if (ops.op_worker_get_type() === "module") { throw new TypeError("Can't import scripts in a module worker."); } @@ -204,8 +205,7 @@ delete Intl.v8BreakIterator; // imported scripts, so we use `loadedMainWorkerScript` to distinguish them. // TODO(andreubotella) Refactor worker creation so the main script isn't // loaded with `importScripts()`. - const scripts = core.opSync( - "op_worker_sync_fetch", + const scripts = ops.op_worker_sync_fetch( parsedUrls, !loadedMainWorkerScript, ); @@ -220,7 +220,7 @@ delete Intl.v8BreakIterator; } function opMainModule() { - return core.opSync("op_main_module"); + return ops.op_main_module(); } function formatException(error) { @@ -243,7 +243,7 @@ delete Intl.v8BreakIterator; core.setMacrotaskCallback(timers.handleTimerMacrotask); core.setMacrotaskCallback(promiseRejectMacrotaskCallback); core.setWasmStreamingCallback(fetch.handleWasmStreaming); - core.opSync("op_set_format_exception_callback", formatException); + ops.op_set_format_exception_callback(formatException); version.setVersions( runtimeOptions.denoVersion, runtimeOptions.v8Version, @@ -569,13 +569,13 @@ delete Intl.v8BreakIterator; function promiseRejectCallback(type, promise, reason) { switch (type) { case 0: { - core.opSync("op_store_pending_promise_exception", promise, reason); + ops.op_store_pending_promise_exception(promise, reason); ArrayPrototypePush(pendingRejections, promise); WeakMapPrototypeSet(pendingRejectionsReasons, promise, reason); break; } case 1: { - core.opSync("op_remove_pending_promise_exception", promise); + ops.op_remove_pending_promise_exception(promise); const index = ArrayPrototypeIndexOf(pendingRejections, promise); if (index > -1) { ArrayPrototypeSplice(pendingRejections, index, 1); @@ -594,8 +594,7 @@ delete Intl.v8BreakIterator; function promiseRejectMacrotaskCallback() { while (pendingRejections.length > 0) { const promise = ArrayPrototypeShift(pendingRejections); - const hasPendingException = core.opSync( - "op_has_pending_promise_exception", + const hasPendingException = ops.op_has_pending_promise_exception( promise, ); const reason = WeakMapPrototypeGet(pendingRejectionsReasons, promise); @@ -613,7 +612,7 @@ delete Intl.v8BreakIterator; const errorEventCb = (event) => { if (event.error === reason) { - core.opSync("op_remove_pending_promise_exception", promise); + ops.op_remove_pending_promise_exception(promise); } }; // Add a callback for "error" event - it will be dispatched @@ -626,7 +625,7 @@ delete Intl.v8BreakIterator; // If event was not prevented (or "unhandledrejection" listeners didn't // throw) we will let Rust side handle it. if (event.defaultPrevented) { - core.opSync("op_remove_pending_promise_exception", promise); + ops.op_remove_pending_promise_exception(promise); } } return true; |