On Thursday, 11 June 2015 at 21:41:27 UTC, Laeeth Isharc wrote:
On Thursday, 11 June 2015 at 21:02:36 UTC, Jonathan M Davis wrote:
The other fun one is the insane number of template instantations we get for stuff like std.algorithm thanks to all of those helper templates like isInputRange. IIRC, std.algorithm's unit tests instantiate over a million different template instances - and much of that is simply for template constraints and static ifs. So, improving build times with regards to templates which are instantiated would probably be the second largest gain to be had behind CTFE if we could improve it, but obviously, we'd have to make such improvements to be sure.

I am following along and learning, but could you perhaps elaborate on this a bit more if you have time. I can see that the unit test
template proliferation makes running unit tests slow for
std.algorithm.  But why does it affect builds in other respects
if you are just importing std.algorithm from a non-phobos code
base? Or was this an example of the extreme case as an illustration?

It's what happens when you use traits like isInputRange, isForwardRange, etc. all over the place. std.algorithm is likely an extreme case, because it's _all_ templated, and it has lots of different static if branches and function overloads for efficiency, and of course, we're talking about the unit tests in particular, so they have to be instantiating all of the various functions in std.algorithm with all kinds of different arguments. You quickly get a combinatorial explosion of template instantiations where a large portion of those templates are eponymous templates used specifically for template constraints and static ifs.

I'd have to track down the posts that Don made on the matter to give any concrete details, but it's was quite surprising to many of us when we found out just how many times many of these basic trait templates were being instantiated.

User code will run into similar problems if it makes heavy use of such templates in template constraints and static if branches and then actually tests all the various combinations in its unit tests, but your average program likely doesn't instantiate stuff like isInputRange anywhere near as much as std.algorithm's unit tests do. It will mostly be unit test builds which have this problem. Still, anything that we can do to improve the compiler's performance in the face of these common idioms will definitely help compilation time.

- Jonathan M Davis

Reply via email to