-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missed private_append optimisation #8106
Comments
I'll take a look Monday. |
Actually dynamic call is not necessary. It's enough to call a remote function: test(X) ->
test(X, <<>>),
test2(X, <<>>).
test(X, Acc) ->
Value = <<Acc/binary, X/binary>>,
e:id(Value).
test2(X, Acc) ->
Value = <<Acc/binary, X/binary>>,
id(Value). |
If you compile the module with The primary target of the private append optimization is a binary that is incrementally built in a loop, and if you give it to a fun or an external function which could capture a reference to the binary, the optimization is no longer safe to do. That the alias pass considers the accumulator aliased is due to a limitation that maybe is possible to remove using the new internal representation brought in by 8fd7153. I'll think about it, but as this is not a regression against OTP 26, I will not make any promises for OTP 27. |
It seems to me as the aliasing analysis is in this case too conservative - whatever Here's my very naive attempt at fixing it: #8108 |
Describe the bug
Given the following code:
the compiler emits a
private_append
concatenation intest2
, but anappend
concatenation intest
.In both cases all the theoretical cases for the optimisation to apply appear - the concatenation starts with an empty binary, and the value appended to is not re-used.
Compiler output
It seems that calling a fun somehow prevents the optimisation in a way that's not documented or expected.
Expected behavior
The compiler should emit a
private_append
concatenation in both cases.Affected versions
Current master as of 78c143f.
The text was updated successfully, but these errors were encountered: