使用V8将JavaScript编译为本机代码 [英] Compile JavaScript to Native Code with V8

查看:145
本文介绍了使用V8将JavaScript编译为本机代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Google的V8引擎,真的有可能将JavaScript编译为本机代码,将其保存为二进制文件,并在任何机器上通过我的软件环境执行它。

Is it really possible, with Google's V8 Engine, to compile JavaScript into Native Code, save it as a binary file, and execute it whenever I want through my software envorinment, on any machine?

推荐答案

您可以使用V8快照功能来预编译代码。这仍然意味着你必须有一个完整版本的V8运行来加载快照(即,你没有获得独立的本地代码,它需要在V8 VM内部运行),所以你保存的是编译时间。
此外,快照代码的质量不一定和JIT代码一样好,因为JIT代码可以使用例如SSE2 / SSE3(如果可用),快照不能假定。

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.

这篇关于使用V8将JavaScript编译为本机代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆