Phobos' slow descent into madness

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri May 7 20:47:57 UTC 2021


So I was looking at this overly beefy compilation with an eye on what 
can cause it take so much memory and time.

Was using -vtemplates and was surprised to see tens of thousands (I mean 
literally: over 45,000 of them) of distinct instantiations of the 
obscure template AliasThisTypeOf.

What the heck is that? Turns out it's a private symbol (that for some 
reason turns out to be duplicated in druntime and phobos). That private 
symbol, in turn, is used in a suite of desperate templates of which 
drabness is only overcome by their mind-numbing repetitiveness:

BooleanTypeOf
IntegralTypeOf
FloatingPointTypeOf
CharTypeOf
StaticArrayTypeOf
DynamicArrayTypeOf
AssocArrayTypeOf

What are these used for? Glad you asked! All these support "alias this" 
for the std.format.format function.

In turn, format turns out to be used, often gratuitously, in very, very 
many places during compilation, particularly in std.traits itself (as an 
aside: format("%s[]")? Really? What happened with good old string 
concatenation?). And that creates an ungodly amount of template 
instantiations. See for yourselves: https://run.dlang.io/is/6j9WI2

But the main problem is the Saturnism that Phobos seems to be suffering 
from. A slow descent into madness.

I do understand the boiling frog slipping on the slippery slope toward 
the road to hell paved with whatever. I do. Heck, I even added a slab 
here and there. But if we look today at the code at 
https://github.com/dlang/phobos/blob/master/std/traits.d#L5819 with the 
sobriety and clearheadedness of a priest on a Sunday morning, the only 
reaction we should have is: "This madness has gotten too far and we must 
stop and turn around RIGHT NOW."

The code in the standard library represents the language, and how we'd 
like people to do things in the language. Sure, we may err on the side 
of optimizing things and throwing in some low-level code for efficiency 
purposes. But this code is not optimization; not algorithms; nothing of 
interest, really. It's mad scaffolding around a temple that should not 
have been built in the first place.

The madness has to stop.


More information about the Digitalmars-d mailing list