IonMonkey now has Scalar Replacement and Branch Pruning optimizations(blog.mozilla.org) |
IonMonkey now has Scalar Replacement and Branch Pruning optimizations(blog.mozilla.org) |
More generally, how should I optimize JS at the level of an individual function? In C++ I would just inspect the emitted assembly code to understand how my code is being compiled. But the assembly seems hard to access in a JS world.
The lastest solution I have seen so far is what we call the "Jit Coach" [2]. This is a devtools panel under the performance tab which reports if your function sticks in IonMonkey compiled code. Based on the MDN page this is behind a preference in "about:config".
When we compile, we record the hypothesis made by the compiler, and use these to annotate the deoptimization paths which are taken. Each time we jump back to Baseline the tool reports why we jump back to Baseline.
So far, only the front-end of IonMonkey and the deoptimization path are recorded. No other optimization phases are recorded at the moment. Sadly, it does not report the Assembly produced by IonMonkey.
[1] https://addons.mozilla.org/en-US/firefox/addon/jit-inspector...
The other writings on that site are worth studying if you want to learn more about how v8 optimizes code [2].
[1] http://mrale.ph/irhydra/2/
[2] http://mrale.ph
(For entertainment purposes, the JITs have names ending in -Monkey.)
TurboFan is a new even-higher-tier, even-more-expensive-to-compile, but potentialy even-more-optimized compiler backend the V8 team is working on.