milomg/js-reactivity-benchmark

Incorrect use of v8 intrinsics

Opened this issue · 0 comments

https://github.com/modderme123/js-reactivity-benchmark/blob/71902bfc0983fe82f3420be856a6419daa3205be/src/molBench.ts#L50

optimizeFunctionOnNextCall optimises the function on the next call but in this case, we've never called it before so there is no feedback. The generated code is going to be not very optimal and then trigger a deopt (potentially).

The correct way to use this intrinsic is to call the function a couple of times (which will trigger feedback collection) and then force compilation with the instrinsic.

Here is an example from the v8 testsuite:


function f(x, y) { return x + y; }

%PrepareFunctionForOptimization(f); // tells v8 to collect feedback
assertEquals(1, f(0, 1));  // feedback is collected
assertEquals(5, f(2, 3)); // feedback is collected
%OptimizeFunctionOnNextCall(f); // tells v8 to optimise based on the collected feedback
assertEquals(9, f(4, 5)); // compilation with type feedback happens
assertOptimized(f);

Separately, I'm not entirely sure why the benchmark wrapper needs to be optimised. Ideally, the signal library should be compiled. I would just remove the intrinsics and call the benchmark function in a smaller loop that warms it up and optimises everything called by it.