Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Try to reduce std::format's size per translation unit #140108

Copy link
Copy link
Open
@cjdb

Description

@cjdb
Issue body actions

Clang generates more than 2.5x the amount of assembly for the sample below when using std::format, as opposed to an inline fmt::format.

#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?

Metadata

Metadata

Assignees

Labels

formatC++20 std::format or std::print, and anything related to themC++20 std::format or std::print, and anything related to themlibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.