[libcxx-commits] [libcxx] [libc++] Add build flags to optimize <format> and <charconv> for code size. (PR #98003)

Robbie Litchfield via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 8 13:15:29 PDT 2024


================
@@ -250,29 +250,79 @@ class __basic_format_arg_value {
     __handle __handle_;
   };
 
+  // Visiting a value for formatting is dispatched via a function pointer to prevent
+  // unused formatters from being instantiated. This can lead to significant code size 
+  // reductions on statically linked targets esp. at lower optimization levels.
+
+  void (__basic_format_arg_value::*__format_)(
+      basic_format_parse_context<_CharT>& __parse_ctx, _Context& __ctx, bool __parse) const;
----------------
BlamKiwi wrote:

Then there is no way to fix your code gen without an ABI break. 

A similar change could be made in `std::make_format_args`, where it generates the minimal visitor function while it still has all the type information. That would still change the size of some types although more palatable to maintain ABI compatibility. __vformat and the arg store would have two versions. 

https://github.com/llvm/llvm-project/pull/98003


More information about the libcxx-commits mailing list