By Jakob Gruber
Translator: Aaron Lee
V8 V7.4 supports JavaScript execution without allocating executable memory at runtime.
In the default configuration of V8, it relies heavily on the ability to allocate and change executable memory at run time. For example, the TurboFan optimized compiler generates native code for hot JavaScript functions in a timely manner, and most JS regular expressions are compiled into native code through the Irregexp engine. Creating executable memory at run time is part of what makes V8 run fast.
However, in some cases it is necessary to run V8 without allocating executable memory:
Some platforms (e.g., iOS, smart TV, game console) need to deny write permissions to executable memory for non-privileged applications, which was previously impossible with V8, and to prevent write permissions to executable memory reduces the number of attack channels for applications.
V8’s new JIT-free mode is designed to address these issues. You can start V8 with the –jitless option to enable JIT free mode.
How does it work? Essentially, V8 switches to interpreter-only mode based on the techniques we’ve implemented. All JS user code runs through the Ignition interpreter [1], and regular expression pattern matching is also interpreted. WebAssembly is not currently supported, but it is possible to interpret implementations. V8’s built-in functions are still compiled to native code, but they are no longer part of the JS managed heap, thanks to our recent efforts to embed them in V8 binaries [2].
Ultimately, these changes allowed us to create V8’s heap without the need for executable permissions on any memory region.
The results of
Because JIT free mode disables the optimized compiler, it comes with a performance penalty. Let’s take a look at V8’s performance characteristics through a number of different benchmarks. Speedometer 2.0 [3] is designed to present test results for typical Web applications. Web Tooling Benchmark [4] contains a common SET of JS developer tools. We also did a benchmark that simulated the browsing workflow of the Living Room YouTube [5] app. All measurements were run locally over 5 times on an X64 Linux desktop.
No JIT mode vs. default V8 mode. The V8 default configuration has a standardized score of 100
Speedometer 2.0 tests show a performance loss of approximately 40% in V8 without JIT mode. Roughly half of this is due to disabling the optimized compiler. The other half is caused by the regular expression interpreter, which was originally used as a debugging aid and will be improved in the future.
Web Tooling Benchmark tended to spend more time on TurboFan optimization code, and as a result its test results showed an even greater performance regression — about 80% — in JIT free mode.
Finally, we measured a simulated browsing session for the Living Room YouTube app, including video playback and menu navigation. This time, JIT-free JS execution was about the same as in standard V8, only about 6% slower. This benchmark demonstrated that peak optimized code performance does not always correlate with actual performance [6], and that in many cases the embedder can maintain reasonable performance even in non-JIT mode.
Loading a representative set of sites shows a 1.7% reduction in the median V8 heap size, with a slight change in memory consumption.
V8 implants are encouraged to consider using V8’s JIT-free mode – available in V8 V7.4 – on limited platforms or when there are special security requirements. As always, please feel free to ask questions or give feedback via the V8 User discussion group [7].
Original: https://v8.dev/blog/jitless
Note:
[1] https://v8.dev/blog/ignition-interpreter
[2] https://v8.dev/blog/embedded-builtins
[3] https://v8.dev/blog/speedometer-2
[4] https://v8.dev/blog/web-tooling-benchmark
[5] https://chromeperf.appspot.com/report?sid=518c637ffa0961f965afe51d06979375467b12b87e72061598763e5a36876306
[6] https://v8.dev/blog/real-world-performance
[7] https://groups.google.com/forum/#! forum/v8-users
Recommended reading:
Orinoco: V8 garbage collector
Async functions and Promise performance optimizations
Please follow our official account