mirror of
https://github.com/denoland/deno
synced 2024-11-05 18:45:24 +00:00
2164f6b1eb
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.
69 lines
1.5 KiB
JavaScript
69 lines
1.5 KiB
JavaScript
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||
"use strict";
|
||
function assert(cond) {
|
||
if (!cond) {
|
||
throw Error("assert");
|
||
}
|
||
}
|
||
|
||
function assertArrayEquals(a1, a2) {
|
||
if (a1.length !== a2.length) throw Error("assert");
|
||
|
||
for (const index in a1) {
|
||
if (a1[index] !== a2[index]) {
|
||
throw Error("assert");
|
||
}
|
||
}
|
||
}
|
||
|
||
function main() {
|
||
// deno-fmt-ignore
|
||
const fixture1 = [
|
||
0xf0, 0x9d, 0x93, 0xbd,
|
||
0xf0, 0x9d, 0x93, 0xae,
|
||
0xf0, 0x9d, 0x94, 0x81,
|
||
0xf0, 0x9d, 0x93, 0xbd
|
||
];
|
||
// deno-fmt-ignore
|
||
const fixture2 = [
|
||
72, 101, 108, 108,
|
||
111, 32, 239, 191,
|
||
189, 239, 191, 189,
|
||
32, 87, 111, 114,
|
||
108, 100
|
||
];
|
||
|
||
const empty = Deno.core.ops.op_encode("");
|
||
if (empty.length !== 0) throw new Error("assert");
|
||
|
||
assertArrayEquals(
|
||
Array.from(Deno.core.ops.op_encode("𝓽𝓮𝔁𝓽")),
|
||
fixture1,
|
||
);
|
||
assertArrayEquals(
|
||
Array.from(Deno.core.ops.op_encode("Hello \udc12\ud834 World")),
|
||
fixture2,
|
||
);
|
||
|
||
const emptyBuf = Deno.core.ops.op_decode(new Uint8Array(0));
|
||
if (emptyBuf !== "") throw new Error("assert");
|
||
|
||
assert(Deno.core.ops.op_decode(new Uint8Array(fixture1)) === "𝓽𝓮𝔁𝓽");
|
||
assert(
|
||
Deno.core.ops.op_decode(new Uint8Array(fixture2)) ===
|
||
"Hello <20><> World",
|
||
);
|
||
|
||
// See https://github.com/denoland/deno/issues/6649
|
||
let thrown = false;
|
||
try {
|
||
Deno.core.ops.op_decode(new Uint8Array(2 ** 29));
|
||
} catch (e) {
|
||
thrown = true;
|
||
assert(e instanceof RangeError);
|
||
assert(e.message === "string too long");
|
||
}
|
||
assert(thrown);
|
||
}
|
||
|
||
main();
|