JuliaLang/julia — comment on commit 3f753435f137cd39afb0ffbdf4fc777efb03c6dd
File:  line 0
By JeffBezanson:

There is going to be an insane amount of overhead here: with_output_stream setting up the current stream including try/catch block for every single print operation, plus the format string function being called each time. Remember the let optimization will only apply for `f"%d %d"(i, i)`.

One thing we can do is get rid of the current output stream. All functions that need it could instead take an explicit stream argument. The default can be `stdout_stream`. Or we could have a julia StringBuilder type that writes into a byte array which eventually gets wrapped as a string.

Also, the current printf doesn't seem to generate very well-specialized code. It does an enormous number of function calls for everything. For `%d`, I would expect something like `write(s, int2str(x))`. Instead there is a function returning four values, then a branch handling the minus sign, then another function call. Then tests for NaN and Inf which should not be needed for an integer format.