Skip to content

<format>: More code bloat when using different iterator types #1883

@vitaut

Description

@vitaut

Describe the bug

There are more code bloat issues similar to #1835, for example, when using vformat_to. This is particularly bad because vformat_to is intended to prevent code bloat and will likely be used for this reason, especially in libraries.

Command-line test case

C:\Temp>type format-one.cc
#include <format>

std::string foo() {
  return std::format("{}", 42);
}

int main() {
  foo();
}

C:\Temp>cl /std:c++latest /EHsc /I STL/stl/inc /O2 format-one.cc STL/stl/src/format.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.29917 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

/std:c++latest is provided as a preview of language features from the latest C++
working draft, and we're eager to hear about bugs and suggestions for improvements.
However, note that these features are provided as-is without support, and subject
to changes or removal as the working draft evolves. See
https://go.microsoft.com/fwlink/?linkid=2045807 for details.

format-one.cc
Microsoft (R) Incremental Linker Version 14.29.29917.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:format-one.exe
format-one.obj

C:\Temp>type format-two.cc
#include <format>
#include <vector>

std::string f() {
  return std::format("{}", 42);
}

std::vector<char> g() {
  std::vector<char> v;
  auto it = std::back_inserter(v);
  using context = std::basic_format_context<decltype(it), char>;
  std::vformat_to(it, "{}", std::make_format_args<context>(42));
  return v;
}

int main() {
  f();
  g();
}

C:\Temp>cl /std:c++latest /EHsc /I STL/stl/inc /O2 format-two.cc STL/stl/src/format.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.29917 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

/std:c++latest is provided as a preview of language features from the latest C++
working draft, and we're eager to hear about bugs and suggestions for improvements.
However, note that these features are provided as-is without support, and subject
to changes or removal as the working draft evolves. See
https://go.microsoft.com/fwlink/?linkid=2045807 for details.

format-two.cc
Microsoft (R) Incremental Linker Version 14.29.29917.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:format-two.exe
format-two.obj

C:\Temp>dir
25.04.2021  07:15           372 224 format-one.exe
25.04.2021  07:16           404 992 format-two.exe

Expected behavior

There should be a small difference between two executable sizes. Currently using a new iterator type results in ~30k binary size increase. For comparison, replacing std::format and std::vformat_to in the above test files with their {fmt}'s counterparts results in ~2.5k increase.

STL version

f675d68

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixedSomething works now, yay!formatC++20/23 formatperformanceMust go faster

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions