Some of the compilation overhead is unavoidable, because we need to parse the format string during constant evaluation. But as it says in this comment in bits/chrono_io.h: // TODO this function template is instantiated for every different _Tp. // Consider creating a polymorphic interface for calendar types so // that we instantiate fewer different specializations. Similar to // _Sink_iter for std::format. Replace each _S_year, _S_day etc. with // member functions of that type. template<typename _Tp, typename _FormatContext> typename _FormatContext::iterator _M_format(const _Tp& __t, _FormatContext& __fc, bool __is_neg = false) const
Created attachment 55579 [details] Instantiate less code for chrono formatters * include/bits/chrono_io.h (__formatter_chrono): Use if-constexpr to avoid instantiating function bodies for types that can never be used with those functions. This patch helps a little bit, but less than I'd hoped it would.
Created attachment 55580 [details] Instantiate less code for chrono formatters, take 2 In this patch the converters like _S_date and _S_hms are called by _M_format before passing the argument to _M_x, _M_d_e etc. so that those function templates are only called with arguments that are already the right type. This reduces the number of different instantiations of those function templates. But this doesn't really help either.
Explicit instantiation declarations+definitions might help, both in <chrono> and <format>.