[libcxx-commits] [libcxx] Speed up std::invoke() compile times (~60%-85% reduction) (PR #213403)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 21 23:48:21 PDT 2026


================
@@ -23,12 +23,34 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _Fn, class... _Args>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 invoke_result_t<_Fn, _Args...>
-invoke(_Fn&& __f, _Args&&... __args) noexcept(is_nothrow_invocable_v<_Fn, _Args...>) {
-  return std::__invoke(std::forward<_Fn>(__f), std::forward<_Args>(__args)...);
+#  if __has_builtin(__builtin_invoke)
+
+template <class... _Args>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<_Args...> invoke(_Args&&... __args)
+    _NOEXCEPT_(noexcept(__builtin_invoke(static_cast<_Args&&>(__args)...))) {
+  return __builtin_invoke(static_cast<_Args&&>(__args)...);
----------------
higher-performance wrote:

Actually... looks like this is bringing back the [pains](https://github.com/llvm/llvm-project/actions/runs/39732557521/job/119671173465?pr=213403) I went through and spent many hours working around last time. :( I neither remember how to fix them again nor whether that will undo the gains I got the first time...

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


More information about the libcxx-commits mailing list