-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Convert List.apply into ::
chains
#18567
Conversation
Related issue: #17035. 👍 |
This is less idiomatic in many cases. Do we have a noticeable performance gain? Note that for large lists the bytecode will be larger which might make it harder for the JIT to optimize some code. |
val pos = s.pos.sourcePos | ||
(pos.line, pos.column) | ||
} | ||
val unsorted = sortedImp ++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has quadratic complexity. Use :::
instead of ++
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to keep the code with the List.apply
and implement the optimization in #17035.
Thank you for the review. |
We should keep the changes from |
Opened another PR here: #18572 |
I don't think there is any complexity difference. Neither
And they both copy the left-hand list — because they must. See also Dale's remark on the new PR. |
Reasoning:
Varargs in Scala use intermediate collections as shown in this example:
compiling with
-Xprint:repeatableAnnotations
gives:I want to avoid instantiating that extra
Array
and wrapping it into anArraySeq
to then create aList
.