<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/140108>140108</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`std::format` generates substantially more code than inlined `fmt::format`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++,
format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
mordante
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cjdb
</td>
</tr>
</table>
<pre>
[Clang generates more than 2.5x the amount of assembly](https://godbolt.org/z/sv56Y1sMz) for the sample below when using `std::format`, as opposed to an inline `fmt::format`.
```cpp
#include <string>
#ifdef USE_LIBFMT
#include <fmt/format-inl.h>
namespace format = fmt;
#else
#include <format>
namespace format = std;
#endif
std::string f(int const x)
{
return format::format("{}", x);
}
```
| Architecture | Options | `std::format` codegen (lines) | `fmt::format` codegen (lines) | Binary size delta |
|--------------|---------|-------------------------------|-------------------------------|--------------------|
| x86_64 | | 2726 | 1013 | std is 2.7x larger |
| x86_64 | -O3 | 3661 | 957 | std is 3.8x larger |
| x86_64 | -Os | 2632 | 908 | std is 2.9x larger |
| armv8-a | | 2594 | 961 | std is 2.7x larger |
| armv8-a | -O3 | 2525 | 941 | std is 2.7x larger |
| armv8-a | -Os | 2429 | 917 | std is 2.6x larger |
Is this something that we can improve upon, or is are the respective libraries designed differently enough that this additional codegen is unavoidable?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVU1v2zgQ_TX0ZWBDGlpfBx3ipAYKbNHD7h72VFDiSGJBkQJJuUl-_YKSk7hxkhaLJQiYpmbe4zxK84T3qjdENcsODHG0TgoTiCGy7G4j5jBYV7ffZbNprHyIUbdamB56MuREIA-jdQRhEAZwl91DGAjEaGcTwHYgvKex0Q8su2NYDiFMnvEbhkeGx97Kxuqws65neHxkePSnLP8n9V8eGVbQWbeAeTFOmqAhbX_Aj4EMzF6ZHlie-CAjGr_prBtFYHnC8BaEBztN1pOEYEEYUEYrQzGh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