-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Performance: override some methods of ArrayBuffer to operate directly on internal array
#11134
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
base: 2.13.x
Are you sure you want to change the base?
Conversation
|
Obviously a tight loop with array indexing must be faster, but how much faster (IRL) and at what cost in code? |
|
I agree, but I want it as fast as Java's ArrayList |
|
Do you know that it is slower? |
|
@Ichoran I don't think Java's ArrayList is slower; Java's ArrayList overrides the |
|
I think the question is: did you test that your change makes There's an existing benchmark class: https://github.com/scala/scala/blob/2.13.x/test/benchmarks/src/main/scala/scala/collection/mutable/ArrayBufferBenchmark.scala. You could add some benchmarks to compare before/after, and also compare to Java's ArrayList. |
|
I got the number with numbers: for 10000 elements only |
|
Okay, that looks pretty compelling! I guess the JIT compiler is not doing a good job eliding the extra work in this case. |
ArrayBuffer to operate directly on internal array
|
With this numbers, adding some overrides looks worthwhile indeed. Questions:
Probably it's worth looking at |
|
I totally missed other types, because I wanted to use the ArrayBuffer as an ArrayDeque. Maybe we should add these optimizations in |
|
I don't think the |
f1d114d to
d8cf863
Compare
Motivation:
I wanted to use ArrayBuffer, but found it does not override the
foreachmethod.refs: apache/pekko#2262
I got the number with numbers:
for 10000 elements only