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

Avi Kivity avi at cloudius-systems.com
Wed Apr 29 14:45:33 UTC 2015


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 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 
<https://github.com/cloudius-systems/seastar>, specifically 
future::then() in core/future.hh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20150429/f6d88451/attachment-0001.html>


More information about the cxx-abi-dev mailing list