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/40_testing.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/40_testing.js')
-rw-r--r-- | runtime/js/40_testing.js | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js index fabdb8dc4..276fef6a6 100644 --- a/runtime/js/40_testing.js +++ b/runtime/js/40_testing.js @@ -3,6 +3,7 @@ ((window) => { const core = window.Deno.core; + const ops = core.ops; const { setExitHandler } = window.__bootstrap.os; const { Console } = window.__bootstrap.console; const { serializePermissions } = window.__bootstrap.permissions; @@ -510,14 +511,13 @@ } function pledgePermissions(permissions) { - return core.opSync( - "op_pledge_test_permissions", + return ops.op_pledge_test_permissions( serializePermissions(permissions), ); } function restorePermissions(token) { - core.opSync("op_restore_test_permissions", token); + ops.op_restore_test_permissions(token); } function withPermissions(fn, permissions) { @@ -709,7 +709,7 @@ columnNumber: jsError.frames[1].columnNumber, }; - const { id, filteredOut } = core.opSync("op_register_test", testDesc); + const { id, filteredOut } = ops.op_register_test(testDesc); testDesc.id = id; testDesc.filteredOut = filteredOut; @@ -731,7 +731,7 @@ return; } - core.opSync("op_bench_check_unstable"); + ops.op_bench_check_unstable(); let benchDesc; const defaults = { ignore: false, @@ -815,7 +815,7 @@ const AsyncFunction = (async () => {}).constructor; benchDesc.async = AsyncFunction === benchDesc.fn.constructor; - const { id, filteredOut } = core.opSync("op_register_bench", benchDesc); + const { id, filteredOut } = ops.op_register_bench(benchDesc); benchDesc.id = id; benchDesc.filteredOut = filteredOut; @@ -1016,20 +1016,20 @@ function getTestOrigin() { if (origin == null) { - origin = core.opSync("op_get_test_origin"); + origin = ops.op_get_test_origin(); } return origin; } function getBenchOrigin() { if (origin == null) { - origin = core.opSync("op_get_bench_origin"); + origin = ops.op_get_bench_origin(); } return origin; } function benchNow() { - return core.opSync("op_bench_now"); + return ops.op_bench_now(); } // This function is called by Rust side if we're in `deno test` or @@ -1051,7 +1051,7 @@ (desc) => !desc.filteredOut, ); - core.opSync("op_dispatch_test_event", { + ops.op_dispatch_test_event({ plan: { origin, total: filtered.length, @@ -1079,11 +1079,11 @@ } for (const desc of filtered) { - core.opSync("op_dispatch_test_event", { wait: desc.id }); + ops.op_dispatch_test_event({ wait: desc.id }); const earlier = DateNow(); const result = await runTest(desc); const elapsed = DateNow() - earlier; - core.opSync("op_dispatch_test_event", { + ops.op_dispatch_test_event({ result: [desc.id, result, elapsed], }); } @@ -1096,7 +1096,7 @@ const originalConsole = globalThis.console; globalThis.console = new Console((s) => { - core.opSync("op_dispatch_bench_event", { output: s }); + ops.op_dispatch_bench_event({ output: s }); }); const only = ArrayPrototypeFilter(benchDescs, (bench) => bench.only); @@ -1120,7 +1120,7 @@ (a, b) => groups.indexOf(a.group) - groups.indexOf(b.group), ); - core.opSync("op_dispatch_bench_event", { + ops.op_dispatch_bench_event({ plan: { origin, total: filtered.length, @@ -1131,8 +1131,8 @@ for (const desc of filtered) { desc.baseline = !!desc.baseline; - core.opSync("op_dispatch_bench_event", { wait: desc.id }); - core.opSync("op_dispatch_bench_event", { + ops.op_dispatch_bench_event({ wait: desc.id }); + ops.op_dispatch_bench_event({ result: [desc.id, await runBench(desc)], }); } @@ -1173,7 +1173,7 @@ if (state.reportedWait) { return; } - core.opSync("op_dispatch_test_event", { stepWait: desc.id }); + ops.op_dispatch_test_event({ stepWait: desc.id }); state.reportedWait = true; } @@ -1194,7 +1194,7 @@ } else { result = state.status; } - core.opSync("op_dispatch_test_event", { + ops.op_dispatch_test_event({ stepResult: [desc.id, result, state.elapsed], }); state.reportedResult = true; @@ -1293,7 +1293,7 @@ stepDesc.parent = desc; stepDesc.rootId = rootId; stepDesc.rootName = rootName; - const { id } = core.opSync("op_register_test_step", stepDesc); + const { id } = ops.op_register_test_step(stepDesc); stepDesc.id = id; const state = { context: createTestContext(stepDesc), |