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 /ext/web | |
| 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 'ext/web')
| -rw-r--r-- | ext/web/00_infra.js | 5 | ||||
| -rw-r--r-- | ext/web/02_timers.js | 5 | ||||
| -rw-r--r-- | ext/web/05_base64.js | 5 | ||||
| -rw-r--r-- | ext/web/08_text_encoding.js | 11 | ||||
| -rw-r--r-- | ext/web/09_file.js | 9 | ||||
| -rw-r--r-- | ext/web/11_blob_url.js | 6 | ||||
| -rw-r--r-- | ext/web/13_message_port.js | 6 | ||||
| -rw-r--r-- | ext/web/14_compression.js | 15 |
8 files changed, 33 insertions, 29 deletions
diff --git a/ext/web/00_infra.js b/ext/web/00_infra.js index bf931f8c7..9a9db5c22 100644 --- a/ext/web/00_infra.js +++ b/ext/web/00_infra.js @@ -10,6 +10,7 @@ ((window) => { const core = Deno.core; + const ops = core.ops; const { ArrayPrototypeJoin, ArrayPrototypeMap, @@ -239,7 +240,7 @@ * @returns {string} */ function forgivingBase64Encode(data) { - return core.opSync("op_base64_encode", data); + return ops.op_base64_encode(data); } /** @@ -247,7 +248,7 @@ * @returns {Uint8Array} */ function forgivingBase64Decode(data) { - return core.opSync("op_base64_decode", data); + return ops.op_base64_decode(data); } /** diff --git a/ext/web/02_timers.js b/ext/web/02_timers.js index a4ce33a18..07b9587ea 100644 --- a/ext/web/02_timers.js +++ b/ext/web/02_timers.js @@ -3,6 +3,7 @@ ((window) => { const core = window.Deno.core; + const ops = core.ops; const { ArrayPrototypePush, ArrayPrototypeShift, @@ -25,7 +26,7 @@ const { assert } = window.__bootstrap.infra; function opNow() { - return core.opSync("op_now"); + return ops.op_now(); } // --------------------------------------------------------------------------- @@ -103,7 +104,7 @@ // TODO(@andreubotella): Deal with overflow. // https://github.com/whatwg/html/issues/7358 id = nextId++; - const cancelRid = core.opSync("op_timer_handle"); + const cancelRid = ops.op_timer_handle(); timerInfo = { cancelRid, isRef: true, promiseId: -1 }; // Step 4 in "run steps after a timeout". diff --git a/ext/web/05_base64.js b/ext/web/05_base64.js index 8238831f8..89c409ae2 100644 --- a/ext/web/05_base64.js +++ b/ext/web/05_base64.js @@ -10,6 +10,7 @@ ((window) => { const core = Deno.core; + const ops = core.ops; const webidl = window.__bootstrap.webidl; const { DOMException } = window.__bootstrap.domException; const { TypeError } = window.__bootstrap.primordials; @@ -26,7 +27,7 @@ context: "Argument 1", }); try { - return core.opSync("op_base64_atob", data); + return ops.op_base64_atob(data); } catch (e) { if (e instanceof TypeError) { throw new DOMException( @@ -50,7 +51,7 @@ context: "Argument 1", }); try { - return core.opSync("op_base64_btoa", data); + return ops.op_base64_btoa(data); } catch (e) { if (e instanceof TypeError) { throw new DOMException( diff --git a/ext/web/08_text_encoding.js b/ext/web/08_text_encoding.js index 282618da3..44087b1de 100644 --- a/ext/web/08_text_encoding.js +++ b/ext/web/08_text_encoding.js @@ -13,6 +13,7 @@ ((window) => { const core = Deno.core; + const ops = core.ops; const webidl = window.__bootstrap.webidl; const { ArrayBufferIsView, @@ -51,7 +52,7 @@ prefix, context: "Argument 2", }); - const encoding = core.opSync("op_encoding_normalize_label", label); + const encoding = ops.op_encoding_normalize_label(label); this.#encoding = encoding; this.#fatal = options.fatal; this.#ignoreBOM = options.ignoreBOM; @@ -124,7 +125,7 @@ } if (!options.stream && this.#rid === null) { - return core.opSync("op_encoding_decode_single", input, { + return ops.op_encoding_decode_single(input, { label: this.#encoding, fatal: this.#fatal, ignoreBom: this.#ignoreBOM, @@ -132,13 +133,13 @@ } if (this.#rid === null) { - this.#rid = core.opSync("op_encoding_new_decoder", { + this.#rid = ops.op_encoding_new_decoder({ label: this.#encoding, fatal: this.#fatal, ignoreBom: this.#ignoreBOM, }); } - return core.opSync("op_encoding_decode", input, { + return ops.op_encoding_decode(input, { rid: this.#rid, stream: options.stream, }); @@ -200,7 +201,7 @@ context: "Argument 2", allowShared: true, }); - return core.opSync("op_encoding_encode_into", source, destination); + return ops.op_encoding_encode_into(source, destination); } } diff --git a/ext/web/09_file.js b/ext/web/09_file.js index 50cce9004..d01858c92 100644 --- a/ext/web/09_file.js +++ b/ext/web/09_file.js @@ -13,6 +13,7 @@ ((window) => { const core = window.Deno.core; + const ops = core.ops; const webidl = window.__bootstrap.webidl; const { ArrayBufferPrototype, @@ -505,7 +506,7 @@ // A finalization registry to deallocate a blob part when its JS reference is // garbage collected. const registry = new FinalizationRegistry((uuid) => { - core.opSync("op_blob_remove_part", uuid); + ops.op_blob_remove_part(uuid); }); // TODO(lucacasonato): get a better stream from Rust in BlobReference#stream @@ -533,7 +534,7 @@ * @returns {BlobReference} */ static fromUint8Array(data) { - const id = core.opSync("op_blob_create_part", data); + const id = ops.op_blob_create_part(data); return new BlobReference(id, data.byteLength); } @@ -548,7 +549,7 @@ */ slice(start, end) { const size = end - start; - const id = core.opSync("op_blob_slice_part", this._id, { + const id = ops.op_blob_slice_part(this._id, { start, len: size, }); @@ -588,7 +589,7 @@ * @returns {Blob | null} */ function blobFromObjectUrl(url) { - const blobData = core.opSync("op_blob_from_object_url", url); + const blobData = ops.op_blob_from_object_url(url); if (blobData === null) { return null; } diff --git a/ext/web/11_blob_url.js b/ext/web/11_blob_url.js index cd9d0929e..9a705f391 100644 --- a/ext/web/11_blob_url.js +++ b/ext/web/11_blob_url.js @@ -14,6 +14,7 @@ ((window) => { const core = Deno.core; + const ops = core.ops; const webidl = window.__bootstrap.webidl; const { getParts } = window.__bootstrap.file; const { URL } = window.__bootstrap.url; @@ -30,8 +31,7 @@ prefix, }); - const url = core.opSync( - "op_blob_create_object_url", + const url = ops.op_blob_create_object_url( blob.type, getParts(blob), ); @@ -51,7 +51,7 @@ prefix, }); - core.opSync("op_blob_revoke_object_url", url); + ops.op_blob_revoke_object_url(url); } URL.createObjectURL = createObjectURL; diff --git a/ext/web/13_message_port.js b/ext/web/13_message_port.js index 19aa0a93b..1fbeeaff7 100644 --- a/ext/web/13_message_port.js +++ b/ext/web/13_message_port.js @@ -10,7 +10,7 @@ ((window) => { const core = window.Deno.core; - const { InterruptedPrototype } = core; + const { InterruptedPrototype, ops } = core; const webidl = window.__bootstrap.webidl; const { setEventTargetData } = window.__bootstrap.eventTarget; const { defineEventHandler } = window.__bootstrap.event; @@ -128,7 +128,7 @@ } const data = serializeJsMessageData(message, transfer); if (this[_id] === null) return; - core.opSync("op_message_port_post_message", this[_id], data); + ops.op_message_port_post_message(this[_id], data); } start() { @@ -193,7 +193,7 @@ * @returns {[number, number]} */ function opCreateEntangledMessagePort() { - return core.opSync("op_message_port_create_entangled"); + return ops.op_message_port_create_entangled(); } /** diff --git a/ext/web/14_compression.js b/ext/web/14_compression.js index a96a7ce43..c56954c74 100644 --- a/ext/web/14_compression.js +++ b/ext/web/14_compression.js @@ -9,6 +9,7 @@ ((window) => { const core = window.Deno.core; + const ops = core.ops; const webidl = window.__bootstrap.webidl; const { TransformStream } = window.__bootstrap.streams; @@ -32,7 +33,7 @@ context: "Argument 1", }); - const rid = core.opSync("op_compression_new", format, false); + const rid = ops.op_compression_new(format, false); this.#transform = new TransformStream({ transform(chunk, controller) { @@ -40,15 +41,14 @@ prefix, context: "chunk", }); - const output = core.opSync( - "op_compression_write", + const output = ops.op_compression_write( rid, chunk, ); maybeEnqueue(controller, output); }, flush(controller) { - const output = core.opSync("op_compression_finish", rid); + const output = ops.op_compression_finish(rid); maybeEnqueue(controller, output); }, }); @@ -81,7 +81,7 @@ context: "Argument 1", }); - const rid = core.opSync("op_compression_new", format, true); + const rid = ops.op_compression_new(format, true); this.#transform = new TransformStream({ transform(chunk, controller) { @@ -89,15 +89,14 @@ prefix, context: "chunk", }); - const output = core.opSync( - "op_compression_write", + const output = ops.op_compression_write( rid, chunk, ); maybeEnqueue(controller, output); }, flush(controller) { - const output = core.opSync("op_compression_finish", rid); + const output = ops.op_compression_finish(rid); maybeEnqueue(controller, output); }, }); |
