AOT/JNI/Vala 的比较

来源:互联网 发布:linux www服务器 编辑:程序博客网 时间:2024/05/07 22:57

转自:

http://en.wikipedia.org/wiki/AOT_compiler

https://wiki.gnome.org/Vala/FAQ#How_does_the_performance_of_Vala_applications_compare_to_other_applications.3F


An ahead-of-time (AOT) compiler is a compiler that implements ahead-of-time compilation. This refers to the act of compiling an intermediate language, such as Java bytecode, .NET Common Intermediate Language (CIL), or IBM System/38 or IBM System i "Technology Independent Machine Interface" code, into a system-dependent binary.

AOT(ahead-of-time 编译方式),就是将 像Java编译后得到的中间语言文件 变成和系统相关的 native binary。


Most languages with a managed code runtime that can be compiled to an intermediate language take advantage of just-in-time (JIT)[citation needed]. This, briefly, compiles intermediate code into machine codefor a native run while the intermediate code is executing, which may decrease an application's performance. Ahead-of-time compilation eliminates the need for this step by performing the compilation before execution rather than during execution.

JIT(just-in-time),相当于解释型语言,运行的时候,相当于是解释一条语句执行一条语句,即将一条中间的托管的语句翻译成一条机器语句,然后执行这条机器语句。执行效率较低。

相比JIT,AOT在运行之前就将中间托管代码翻译成了机器代码,不存在JIT的“执行期的翻译”步骤,所以执行效率比JIT高。


AOT compilation is mostly beneficial in cases where the interpreter (which is small) is too slow or JIT is too complex or introduces undesirable latencies.[citation needed] In most situations with fully AOT compiled programs and libraries it is possible to drop considerable fraction of runtime environment, thus saving disk space, memory and starting time. Because of this it can be useful in embedded or mobile devices.

AOT主要适用场合是,当解释器(中间语言翻译成机器语言)速度太慢,或JIT过于复杂,或JIT导致严重的滞后的情况。大多数情况下,启用了AOT以后的可执行程序,相比启用AOT之前,可以摒弃很多运行时环境的碎片(fraction of runtime environment),从而节省磁盘/内存空间,缩短启动时间。因此,AOT在嵌入式设备和移动设备中是很有用的。


AOT in most cases produces machine optimized code, just like a 'standard' native compiler. The difference is that AOT transforms the bytecode of an existing virtual machine into machine code. AOT compilers can perform complex and advanced code optimizations which in most cases of JITing will be considered much too costly. On the other hand AOT can't usually perform some optimizations possible in JIT, like runtime profile-guided optimizations, pseudo-constant propagation or indirect/virtual function inlining.

大多数情况下,AOT都可以将二进制代码针对硬件做优化,这时的AOT就很想一个真正的本地编译器,比如gcc。AOT和真正的本地编译器的不同之处在于,AOT是将现有的虚拟机的字节码转成本机二进制码,即操作对象和真正的编译器不同。AOT编译器可以执行高级的复杂的字节码的优化,这些优化对JIT来说,大多数都代价太高。另一方面,通常AOT不能执行一些JIT能做到的优化,比如 runtime profile-guided optimizations, pseudo-constant propagation or indirect/virtual function inlining。


How does the performance of Vala applications compare to other applications?

The performance should be pretty similar to GObject/C-based code as there is no Vala-specific runtime library/environment that needs to be loaded. The C compiler can also apply the same optimizations on Vala-generated C code and plain GObject/C code. The Vala compiler uses reference counting in more places than most GObject/C-based applications do. However, Vala allows to fine-tune that easily in performance-critical sections with the weak modifier.

Vala application和其他语言的application的执行效率的比较

Vala application的执行效率类似 GObject/C-based 代码的执行效率,因为Vala没有自己额外的运行时库和运行时环境要加载。C编译器可以对用Vala生成的C代码或GObject/C代码做相同的优化。Vala编译器在大多数情况下比GObject/C-based applications使用更多的引用计数。但是,Vala允许对“性能敏感”的部分通过weak modifier做微调。


原创粉丝点击