[cxx-abi-dev] Long compile times due mangling of return types in function templates

John McCall rjmccall at apple.com
Mon Feb 29 18:06:06 UTC 2016


> On Apr 29, 2015, at 7:45 AM, Avi Kivity <avi at cloudius-systems.com> wrote:
> As per the Itanium ABI gcc mangles the return types of function templates, so that we can see mangled names like
> 
>   _Z1hIiEDTplcl1fIT_EEcl1gIS0_EEEv
> 
> which demangle to
> 
>   decltype (((f<int>)())+((g<int>)())) h<int>()
> 
> In seastar [1] this causes serious compile-time performance problems.  Replacing complicated template argument dependent return types improves compile time and object size by around 10%.
> 
> What is the reason that the ABI mandates mangling the return type into the function name?

The ABI only calls for this for function templates, where it is required because function templates with different dependent signatures are distinct templates; q.v. [temp.over.link].

John.




> 
> 
> 
> The patch below (replacing return types with auto) gave me about 10% compile time improvement:
> 
> --- a/core/future.hh
> +++ b/core/future.hh
> @@ -460,7 +460,8 @@ private:
>      }
>       template <typename Ret, typename Func, typename Param>
> -    futurize_t<Ret> then(Func&& func, Param&& param) noexcept {
> +    auto // futurize_t<Ret>
> +    then(Func&& func, Param&& param) noexcept {
>          using futurator = futurize<Ret>;
>          using P = typename futurator::promise_type;
>          if (state()->available() && (++future_avail_count % 256)) {
> @@ -526,12 +527,14 @@ public:
>      }
>       template <typename Func>
> -    futurize_t<std::result_of_t<Func(T&&...)>> then(Func&& func) noexcept {
> +    auto // futurize_t<std::result_of_t<Func(T&&...)>>
> +    then(Func&& func) noexcept {
>          return then<std::result_of_t<Func(T&&...)>>(std::forward<Func>(func), [] (future_state<T...>&& state) { return state.get(); });
>      }
>       template <typename Func>
> -    futurize_t<std::result_of_t<Func(future<T...>)>>
> +    auto
> +    //futurize_t<std::result_of_t<Func(future<T...>)>>
>      then_wrapped(Func&& func) noexcept {
>          return then<std::result_of_t<Func(future<T...>)>>(std::forward<Func>(func), [] (future_state<T...>&& state) { return future(std::move(state)); });
>      }
> 
> 
> 
> 
> [1] https://github.com/cloudius-systems/seastar, specifically future::then() in core/future.hh
> _______________________________________________
> cxx-abi-dev mailing list
> cxx-abi-dev at codesourcery.com
> http://sourcerytools.com/cgi-bin/mailman/listinfo/cxx-abi-dev



More information about the cxx-abi-dev mailing list