1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00
denoland-deno/cli/bench/deno_common.js
Aapo Alasuutari 2164f6b1eb
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.
2022-08-11 15:56:56 +02:00

72 lines
1.6 KiB
JavaScript

// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
// v8 builtin that's close to the upper bound non-NOPs
Deno.bench("date_now", { n: 5e5 }, () => {
Date.now();
});
// Void ops measure op-overhead
Deno.bench(
"op_void_sync",
{ n: 1e7 },
() => Deno.core.ops.op_void_sync(),
);
Deno.bench(
"op_void_async",
{ n: 1e6 },
() => Deno.core.opAsync("op_void_async"),
);
// A very lightweight op, that should be highly optimizable
Deno.bench("perf_now", { n: 5e5 }, () => {
performance.now();
});
// A common "language feature", that should be fast
// also a decent representation of a non-trivial JSON-op
{
let i = 0;
Deno.bench("url_parse", { n: 5e4 }, () => {
new URL(`http://www.google.com/${i}`);
i++;
});
}
Deno.bench("blob_text_large", { n: 100 }, () => {
new Blob([input]).text();
});
const input = "long-string".repeat(99999);
Deno.bench("b64_rt_long", { n: 100 }, () => {
atob(btoa(input));
});
Deno.bench("b64_rt_short", { n: 1e6 }, () => {
atob(btoa("123"));
});
{
const buf = new Uint8Array(100);
const file = Deno.openSync("/dev/zero");
Deno.bench("read_zero", { n: 5e5 }, () => {
Deno.readSync(file.rid, buf);
});
}
{
// Not too large since we want to measure op-overhead not sys IO
const dataChunk = new Uint8Array(100);
const file = Deno.openSync("/dev/null", { write: true });
Deno.bench("write_null", { n: 5e5 }, () => {
Deno.writeSync(file.rid, dataChunk);
});
}
Deno.bench(
"read_128k",
{ n: 5e4 },
() => Deno.readFile("./cli/bench/testdata/128k.bin"),
);
Deno.bench("request_new", { n: 5e5 }, () => new Request("https://deno.land"));