-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
String concatenation is slow in later versions of fmt #3133
Comments
The reason why godbolt results are slow is because the {fmt} library deployed there is compiled with optimizations disabled. Here are the results on macOS with optimizations enabled:
Runtime |
Specifically we should inline copying in https://godbolt.org/z/bxabqfv3G:
It was made noinline to reduce code bloat elsewhere but this doesn't make sense for compilation. |
Thanks for looking into it @vitaut . Maybe a dumb question but is there a reason we don't know the size of the string (at least in specific cases, like when all parameters to |
In principle it should be possible to do reserve once in cases like this but it's not implemented yet. |
Format string compilation has been optimized for this and similar cases in 1daae55.
|
Thank you for working on this @vitaut ! Curious to see |
The remaining difference (which is minor in this case) may come from the fact that we still don't reserve in advance. It is possible to do but the RoI is low. |
Oh I see. Yeah, it'd be roughly ~10% I guess. Worth opening an issue for it, maybe someone someday will do it? |
We don't such things as issues but a PR would be welcome. |
Running the concat-benchmark both on godbolt and on a local machine, the fmt string concatenation tests are slower than the naive case (tested with 9.1.0 and master). With godbolt I had trouble compiling with anything but trunk, however, on a local machine I tested with gcc 11.2.0 and 12.1.0. On godbolt the runtime test is very slow whereas on my machine the runtime test is slower but at least close to the naive implementation.
I found the results surprising. At least at one time I know fmt was close to on par with the append test.
The text was updated successfully, but these errors were encountered: