microsoft / microsoft/STL

`<chrono>`: Can we avoid including `<format>`?

Open
#2,003 2 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

chrono format throughput
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

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:

https://github.com/microsoft/STL/blob/4c862ee11ce956556b810a813e77b0f8f97fb642/stl/inc/chrono#L37-L40

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 .

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at stl/inc/chrono lines 37-40 and trace why includes , including the formatter declarations and standard lookup requirements. Evaluate the proposed forward declarations or shared machinery, with completion requiring removal of the unnecessary dependency without violating the standard or regressing compilation throughput.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.