-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Allocating empty array is 4x slower than Java #45160
Comments
What would be fast? It feels to me that for an issue like this to be useful at all it either needs some comparison to e.g. a different language that has the same semantics for creating an empty array or an analysis of what the time is spent on and what of that is wasteful. Otherwise, issues like this can be created for virtually any function and it is unclear when they can be closed. |
Isn't that just the performance of
I assume one extra allocation is due to need to keep |
Arguably we should be faster than malloc though. |
Well, it might be possible, but does it make sense to benchmark allocation function without any context? It is possible to return instantly and shift all of the complexity from allocation to the garbage collection later on (as Java does), but it does not make an application faster. |
Yes, as it is right now, it just feels like a blanket "Julia's allocation/GC system could be faster"-issue. Does it help getting any work done? |
the reason I made this is I was bench-marking JuliaMath/Primes.jl#115 and saw that creating an empty |
For reference,
|
I think I've figured out the problem. All the time is in the C function |
Couldn't we pass the info to C anyway? Since array allocation is already special cased? |
One solution to prevent thousands+ of allocations is to use pool of reusable objects. |
That is technically possible, but really annoying. It would be way better if this was fast by default. |
Might this be addressed by #46015 ? |
Partially addressed by #51319? On 1.9.3 I get
on 909bcea instead
|
@giordano can you add |
Not much different
|
So all in all, I think this is closable. It's still a little slow, but it is noticeably faster than before. |
This seems unreasonably slow. It feels like we should be able to do better here.
while with Java
(using jmh to benchmark) gives 4.5ns per iteration
Note that the
push!
isn't the slow part, I just needed it to make sure Java wasn't removing the whole thing since without it, the Java time was sub ns per operation.The text was updated successfully, but these errors were encountered: