[cfe-dev] Massive performance regression in clang 3.9

Andy Gibbs via cfe-dev cfe-dev at lists.llvm.org
Thu Oct 20 23:08:06 PDT 2016


On Wednesday 19 Oct 2016 15:39:30 Richard Smith wrote:
> As of r284653, the performance and memory usage for simple sizeof...
> expansions should be a lot better.

Wonderful!  Brilliant!  Thanks!  We're now within a shade of the compilation 
time of gcc again.  Memory consumption is back to a much more reasonable 
400Mb.

> But your approach is still O(N^2 log N)
> when compiled with Clang. You can remove a factor of N by passing around
> the size of the pack instead of recomputing it [...]

And this makes a huge difference, decreasing the compile time to a mere second.  
Thanks for the suggestion.  It is one worth remembering.  Intuitively it seems 
that sizeof... should just "know" the size of the pack (i.e. O(1) lookup) in 
the way that the normal sizeof "knows" the size of an object, but obviously it 
isn't the case.

As mentioned before, libc++ uses a similar such construct here:

http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__tuple?revision=280007&view=markup#l86

(granted, not for more recent versions of clang, but I think still used with 
gcc for example)

It would probably be worth doing the same trick here, especially as sizeof... 
is calculated seven times.  I should have some time later when I can put 
together a patch.

Thanks again,
Andy





More information about the cfe-dev mailing list