HiPE(High Performance Erlang) 霸爷有一个一语中的的描述"erlang的hipe相当于jit, 根据语言评测有hipe支持在纯erlang的运算上会快2-3倍,这个性能的提升对于计算密集型的应用还是比较可观的。"
编译启用HIPE选项可以这样:c(Module,[native,{hipe,HipeOptions}|MoreOptions). 或者在Emakefile添加对应的配置节;
关于hipe选项的可用参数,我们可以通过hipe:help_options()查看,下面是在我机器上的执行结果:
Erlang R14B03 (erts-5.8.4) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.4 (abort with ^G) 1> hipe:help_options(). HiPE Compiler Options Boolean-valued options generally have corresponding aliases `no_...', and can also be specified as `{Option, true}' or `{Option, false}. General boolean options: [debug,load,pp_asm,pp_beam,pp_icode,pp_native,pp_rtl,time,timeout,verbose]. Non-boolean options: o#, where 0 =< # =< 3: Select optimization level (the default is 2). Further options can be found below; use `hipe:help_option(Name)' for details. Aliases: pp_all = [pp_beam,pp_icode,pp_rtl,pp_native], pp_sparc = pp_native, pp_x86 = pp_native, pp_amd64 = pp_native, pp_ppc = pp_native, o0, o1 = [inline_fp,pmatch,peephole], o2 = [icode_range,icode_ssa_const_prop,icode_ssa_copy_prop,icode_type, icode_inline_bifs,rtl_lcm,rtl_ssa,rtl_ssa_const_prop,spillmin_color, use_indexing,remove_comments,concurrent_comp,binary_opt] ++ o1, o3 = [{regalloc,coalescing},icode_range] ++ o2. ok
Note: another option is to compile your Erlang module to native code. Native code compiling is not available for every platform and OS, but on those that support it, it can make your programs go faster (about 20% faster, based on anecdotal evidence). To compile to native code, you need to use the hipe
module and call it the following way: hipe:c(Module,OptionsList).
You could also use c(Module,[{hipe,o3}]).
when in the shell to achieve similar results. Note that the .beam file generated will no longer be portable across platforms like regular ones.
上面这幅图来自: All you wanted to know about the HiPE compiler [PDF]
启用了HiPE的Erlang/OTP编译流程大体如下:
Erlang/OTP运行时并存两种代码BEAM-code和native-code 这两种代码的互相调用由运行时负责适配,对用户这是透明的.
Core Erlang 1.0.3 language specification [Link] 之前已经多次通过查看Core Erlang代码的方式去分析问题,还是颇有用的。
转自 :http://www.cnblogs.com/me-sa/archive/2012/10/09/erlang_hipe.html