Compile JavaScript to Native Code with V8

五迷三道 提交于 2019-11-27 14:20:01

You can use the V8 snapshot functionality to precompile the code. This still means that you have to have a full version of V8 running to load the snapshot (i.e., you don't get stand-alone native code, it needs to run inside the V8 VM), so all you save is the compilation time. Also, the quality of snapshot code isn't necessarily as good as JIT'ed code because JIT code can use, e.g., SSE2/SSE3 if it's available, which snapshots can't assume.

As far as I know, V8 is purely a just-in-time compiler, and does not have an ahead-of-time option.

As discussed at the articles I linked, JITs allow better, more flexible optimizations.

Jack Nock

Instead, it might be possible to use a .NET JavaScript/JScript compiler to create a .NET exe, then convert the .NET exe to a native .exe using the Mono ahead-of-time compiler.

Instead of using V8, you could compile JavaScript into Python using Js2Py, and then convert the Python source into C++ using the ShedSkin compiler. I haven't tested this approach yet, but it's an interesting possibility nonetheless.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!