-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
use concat(+join) for += #2256
Comments
after discussing in #rubinius the proper behavior would be |
Did you benchmark I don't think that However, I do believe that Python behaves as you're saying you would like Ruby to. I know that because I found that my lists were being mutated when I wasn't expecting them to be! |
as mentioned above I did and it is slower, I think now the simplest move would be to update docs to be more explicit about the differences between |
The change you're discussing would be much larger than just modifying Array behavior. Since += expands to a = a + b in the parser/compiler, we'd have to change += to parse as a method call or modify the compilers to emit some special guard logic that can concat when it detects an Array. I don't think either change is likely to be accepted. The latter change, however, could be done in JRuby or JRuby+Truffle if we added an instruction/node for += that did the guard+optimized logic using JVM capabilities. I'm dubious on the value, since it's generally well-known that += causes more allocation and copying than << or concat. |
I see now it makes not much sense, close if you don't want to work on the optimization |
I will close this but will also add an optimization thought. If we know origin of 'a' and we know nothing is holding a reference to 'a' we could potentially just change the id on original id and concat! into the original. With that idea out there I think the number of places where these conditions exist might make that effort not worh it... |
let's see what MRI does => https://bugs.ruby-lang.org/issues/10560 |
at start I want to accent this is also slow in MRI:
with result:
I understand that the
[]+[]
has to create copy of array, but for[]+=[]
I expect it to behave likeconcat
, not sure if this can or should be optimized.opening first here, will follow with a ticket for MRI if it can be improved.
The text was updated successfully, but these errors were encountered: