This was unexpected, but
show(io::IO, i::Int) does allocate.
It’s clearly happening because printing an integer first converts it to a string and then writes a string to
io: julia/show.jl at v1.6.0 · JuliaLang/julia · GitHub
@btime print(io, 1) # > 100.949 ns (2 allocations: 96 bytes)
Is there any rationale for doing it this way and not another way? Print number to IOBuffer and then convert that to a string seems a more straightforward way to implement it.
Performance of IO-based version should theoretically be superior, but it depends on what and how you measure, as usual
My main question I guess is whether anyone ran into similar issues, and if you think there’s a room for improving standard integer serialization.