This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] [add changelog] reduce template instantiation depth in <variant>


On Sun, Nov 13, 2016 at 10:53 AM, Barrett Adair wrote:
> My last benchmark didn't have any short-circuiting. Here's a benchmark where
> the first type is not default-constructible, copy-constructible, or
> move-constructible:
>
> http://output.jsbin.com/himusodozu
>

This is interesting result!

I saw a slight slow-down after the change, even for 20 alternatives.
So I'm not sure which way to go.

Do you have a concrete use case of creating a variant with 400 alternatives?

> Ruby template for the benchmark:
>
> #include <variant>
> #include <memory>
>
> int main(int argc, char**) {
>
> #if defined METABENCH
>
>     struct T {
>         int i;
>         std::unique_ptr<int> x;
>         T(int i) : i(i), x(nullptr) {}
>     };
>
>     <% (0..n).each do |i| %>
>     struct T<%= i %> { int i; std::string x; };
>     <% end %>
>
>     using var = std::variant< T, T<%= (0..n).to_a.join(', T') %> >;
>
>     var x(T{0});
>     std::visit([](auto&& v){}, x);
>
> #endif
> }



-- 
Regards,
Tim Shen


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]