sys_core_bsm: Rearrange arguments to enable delayed sub binary creation #1687
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Argument order can prevent the delayed sub binary creation.
Here is an example directly from the Efficiency Guide:
When compiling with the
bin_opt_info
option, there will be asuggestion to change the argument order.
It turns out
sys_core_bsm
can itself change the order, not theorder 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:
When rewritten like this, the
bs_start_match2
instruction will bethe 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 positionof the pattern as an argument.
We will update the Efficiency Guide in a separate branch before the
release of OTP 21.