summaryrefslogtreecommitdiff
path: root/cli/js/40_testing.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-07-17 23:17:28 +0200
committerGitHub <noreply@github.com>2023-07-17 21:17:28 +0000
commit298e4149368b23fee573fa27f1a00e0c50828c8c (patch)
tree0c19422b12b3d04f944bddfb99c891b6d59c45b0 /cli/js/40_testing.js
parent4ebe3bdb06a4d539cc8991e1241aa3150100f866 (diff)
fix(bench): run warmup benchmark to break JIT bias (#19844)
Closes https://github.com/denoland/deno/issues/15277 This commit adds a single "warmup" run of empty function when running `deno bench`. This change will break so-called "JIT bias" which makes V8 optimize the first function and then bail out of optimization on second function. In essence the "warmup" function is getting optimized and then all user benches are bailed out of optimization.
Diffstat (limited to 'cli/js/40_testing.js')
-rw-r--r--cli/js/40_testing.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/cli/js/40_testing.js b/cli/js/40_testing.js
index 3058fcee3..740e950a3 100644
--- a/cli/js/40_testing.js
+++ b/cli/js/40_testing.js
@@ -685,6 +685,8 @@ function test(
});
}
+let registeredWarmupBench = false;
+
// Main bench function provided by Deno.
function bench(
nameOrFnOrOptions,
@@ -695,6 +697,25 @@ function bench(
return;
}
+ if (!registeredWarmupBench) {
+ registeredWarmupBench = true;
+ const warmupBenchDesc = {
+ name: "<warmup>",
+ fn: function warmup() {},
+ async: false,
+ ignore: false,
+ baseline: false,
+ only: false,
+ sanitizeExit: true,
+ permissions: null,
+ warmup: true,
+ };
+ warmupBenchDesc.fn = wrapBenchmark(warmupBenchDesc);
+ const { id, origin } = ops.op_register_bench(warmupBenchDesc);
+ warmupBenchDesc.id = id;
+ warmupBenchDesc.origin = origin;
+ }
+
let benchDesc;
const defaults = {
ignore: false,
@@ -777,6 +798,7 @@ function bench(
const AsyncFunction = (async () => {}).constructor;
benchDesc.async = AsyncFunction === benchDesc.fn.constructor;
benchDesc.fn = wrapBenchmark(benchDesc);
+ benchDesc.warmup = false;
const { id, origin } = ops.op_register_bench(benchDesc);
benchDesc.id = id;