-
-
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
show(io, x::Int) allocates #41396
Comments
Possible duplicate of #39041 Ah, no, those are different codepaths. |
Yep, seems unrelated. To be clear, the allocation issue stems from here: https://github.com/JuliaLang/julia/blob/v1.6.0/base/show.jl#L969 and eventually here: https://github.com/JuliaLang/julia/blob/master/base/intfuncs.jl#L688 As you can see, a new string is allocated for every show() call. |
👍 Yes, I think this is always worth optimizing. |
I've dug around in this code too much, I keep thinking of other unrelated things like #40718 that are in a similar situation
Please don't hesitate to open one! |
Feel free to chip in on that PR |
The current implementation of show(io, x::Int) converts int to string and then show()s that string. This obviously causes an allocation and suboptimal.
My benchmarks show considerable performance difference:
print_int() here is my version based on the library code, that reuses thread-local buffers, to remove unnecessary allocations.
The same problem exists for printing floats:
I have some code that I adapted from the library for my narrow needs. I can prepare a PR if someone is interested enough to review that.
The text was updated successfully, but these errors were encountered: