title: optimizing of std::visit possible?
body: <p>While using <code>std::visit</code> / <code>std::variant</code> I see in the profiler output that <code>std::__detail::__variant::__gen_vtable_impl</code> functions take the most time.</p>
  
  <p>I did a test like this:</p>
  
  <pre><code>// 3 class families, all like this
  class ElementDerivedN: public ElementBase
  {
      ...
          std::variant&lt;ElementDerived1*, ElementDerived2*,... &gt; GetVariant() override { return this; }
  }
  
  std::vector&lt;Element*&gt; elements;
  std::vector&lt;Visitor*&gt; visitors;
  std::vector&lt;Third*&gt;   thirds;
  
  // prepare a hack to get dynamic function object:
  template&lt;class... Ts&gt; struct funcs : Ts... { using Ts::operator()...; };
  template&lt;class... Ts&gt; funcs(Ts...) -&gt; funcs&lt;Ts...&gt;;
  
  // demo functions:
  struct Actions { template &lt; typename R, typename S, typename T&gt; void operator()( R*, S*, T* ) {} };
  struct SpecialActionForElement1{ template &lt; typename S, typename T &gt; void operator()( Element1*, S*, T* ) {} };
  
  
  for ( auto el: elements )
  {
      for ( auto vis: visitors )
      {
          for ( auto th: thirds )
          {
              std::visit( funcs{ Actions(), SpecialActionForElement1Derived1()}, el-&gt;GetVariant(), vis-&gt;GetVariant(), th-&gt;GetVariant() );
          }
      }
  }
  </code></pre>
  
  <p>As said, <code>std::__detail::__variant::__gen_vtable_impl&lt;...&gt;</code> takes the most amount of time.</p>
  
  <p>Q:
  As the generated n-dimensional function array generated at each visit call is from call to call the same, it would be nice to keep it between the calls of <code>std::visit</code>. Is that possible?</p>
  
  <p>Maybe I am on the wrong path, if so, let me know!</p>
  
  <p>EDIT:
  used compiler gcc7.3 from standard fedora installation. std-lib is used as standard in g++ ( what ever this is )</p>
  
  <p>build options:</p>
  
  <pre><code>g++ --std=c++17 -fno-rtti main.cpp -O3 -g -o go
  </code></pre>