diff options
author | Björn Gustavsson <[email protected]> | 2018-01-15 11:25:53 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2018-01-16 15:01:34 +0100 |
commit | ee072786553683dcd2947a3a432da68a79c05b63 (patch) | |
tree | dcf0aac6db976da0499554983aff58a784a04b21 /bootstrap/lib/kernel/ebin/file_server.beam | |
parent | fd30cdac0f62c70336330d94ac944bb110932cc2 (diff) | |
download | otp-ee072786553683dcd2947a3a432da68a79c05b63.tar.gz otp-ee072786553683dcd2947a3a432da68a79c05b63.tar.bz2 otp-ee072786553683dcd2947a3a432da68a79c05b63.zip |
sys_core_bsm: Rearrange arguments to enable delayed sub binary creation
Argument order can prevent the delayed sub binary creation.
Here is an example directly from the Efficiency Guide:
non_opt_eq([H|T1], <<H,T2/binary>>) ->
non_opt_eq(T1, T2);
non_opt_eq([_|_], <<_,_/binary>>) ->
false;
non_opt_eq([], <<>>) ->
true.
When compiling with the bin_opt_info option, there will be a
suggestion to change the argument order.
It turns out sys_core_bsm can itself change the order, not the
order of the arguments of themselves, but the order in which
the arguments are matched. Here is how it can be rewritten in
pseudo Core Erlang code:
non_opt_eq(Arg1, Arg2) ->
case < Arg2,Arg1 > of
< <<H1,T2/binary>>, [H2|T1] > when H1 =:= H2 ->
non_opt_eq(T1, T2);
< <<_,T2/binary>ffff>, [_|T1] > ->
false;
< <<>>, [] >> ->
true
end.
When rewritten like this, the bs_start_match2 instruction will be
the first instruction in the function and it will be possible to
store the match context in the same register as the binary
({x,1} in this case) and to delay the creation of sub binaries.
The switching of matching order also enables many other simplifications
in sys_core_bsm, since there is no longer any need to pass the position
of the pattern as an argument.
We will update the Efficiency Guide in a separate branch before the
release of OTP 21.
Diffstat (limited to 'bootstrap/lib/kernel/ebin/file_server.beam')
0 files changed, 0 insertions, 0 deletions