Skip to content

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

Description

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 .

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    chronoC++20 chronoformatC++20/23 formatthroughputMust compile faster

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions