Open green-nsk opened 3 years ago
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.
:+1: 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
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.
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.