Skip to content
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

<chrono>: Can we avoid including <format>? #2003

Open
StephanTLavavej opened this issue Jun 11, 2021 · 2 comments
Open

<chrono>: Can we avoid including <format>? #2003

StephanTLavavej opened this issue Jun 11, 2021 · 2 comments
Labels
chrono C++20 chrono format C++20/23 format throughput Must compile faster

Comments

@StephanTLavavej
Copy link
Member

StephanTLavavej commented Jun 11, 2021

On reddit, u/tgolyi reports:

std::format is very cool, but why did you include <format> to <chrono>? This change alone slowed down compilation for our project by 20%. Is it required by the standard now to include <format> (to support std::formatter specialization)? It's just that <chrono> is included by so many other headers like <mutex> and <thread> and Qt too.

Separately from any throughput improvements for <format>, I believe it should be possible to remove this dependency:

STL/stl/inc/chrono

Lines 37 to 40 in 4c862ee

#ifdef __cpp_lib_format
#include <format>
#include <iomanip>
#endif // defined(__cpp_lib_format)

The fix would presumably involve some combination of:

  • Forward declarations (of formatter etc.)
  • Extracting common machinery to a centralized header somewhere (used sparingly, since this costs throughput)
  • Possibly templatizing stuff so that it isn't instantiated until needed (need to follow the Standard's lookup rules)

Related to DevCom-10046069 "Including chrono and compiling with -std:c++20 is ten time slower than before" and internal VSO-1543202 / AB#1543202 .

@StephanTLavavej StephanTLavavej added throughput Must compile faster format C++20/23 format chrono C++20 chrono labels Jun 11, 2021
@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Jan 13, 2022

Including <format> not only slows down compilation, but also drags in some codes for dynamic initialization (https://godbolt.org/z/8njf5E85q https://godbolt.org/z/x98Tqexaq).

Oh... it seems that this issue disappears if the workaround for #2329 is removed. This issue has been fixed reduced, but not fixed, by #2496.

@frederick-vs-ja
Copy link
Contributor

Partially addressed by #2600.

Implementations of some operator<<s in <chrono> are currently dependent on std::format, which is requiring almost everything in <format>. IMO removing the dependence on <format> essentially needs implementing these operator<<s in some alternative ways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chrono C++20 chrono format C++20/23 format throughput Must compile faster
Projects
None yet
Development

No branches or pull requests

2 participants