Skip to content

Instantly share code, notes, and snippets.

Created May 17, 2014
What would you like to do?
Erlangコード最適化メモ: JSONデコード処理(2): HiPEを使う ref:
$ erl
Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:2:2] [async-threads:10] [hipe]
Eshell V5.10.4 (abort with ^G)
%% nativeをコンパイルオプションに、指定するとHiPEコンパイラが使われる
> c(hoge, [native]).
{ok, hoge}.
%% hipe:help/0 でヘルプが表示できる
> hipe:help().
The HiPE Compiler (Version
The normal way to native-compile Erlang code using HiPE is to
include `native' in the Erlang compiler options, as in:
1> c(my_module, [native]).
Options to the HiPE compiler must then be passed as follows:
1> c(my_module, [native,{hipe,Options}]).
Use `help_options()' for details.
Utility functions:
Prints this message.
Prints a description of options recognized by the
HiPE compiler.
Prints a description of that option.
Prints a description of debug options.
version() ->
Returns the HiPE version as a string'.
For HiPE developers only:
Use `help_hiper()' for information about HiPE's low-level interface
%% 最適化レベルが選べたりもする (o3が最高, デフォルトはo2)
> c(hoge, [native, {hipe, [o3]}]).
{ok, hoge}.
%% HiPE無しでコンパイルした場合
> json_decode_1:decode(<<"[1,2,]">>). % 不正なJSONを渡す
** exception error: bad argument
in function json_decode_1:value/1
called as json_decode_1:value(<<"]">>) % 引数情報がつく
in call from json_decode_1:array/2 (json_decode_1.erl, line 44) % 行番号もつく
in call from json_decode_1:decode/1 (json_decode_1.erl, line 18)
%% HiPE有りでコンパイルした場合
> json_decode_1:decode(<<"[1,2,]">>).
** exception error: bad argument
in function json_decode_1_hipe:value/1 % 関数名のみ
in call from json_decode_1_hipe:array/2
in call from json_decode_1_hipe:decode/1
in call from lists:reverse/1 % 何故か経由していないはずの関数が含まれている
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment