Update on the D-to-Jai guy: We have real problems with the language

Steven Schveighoffer schveiguy at gmail.com
Tue Nov 29 01:58:48 UTC 2022


On 11/28/22 5:27 PM, Walter Bright wrote:
> On 11/27/2022 8:12 AM, Steven Schveighoffer wrote:
>> I still have some hope that there are ways to decrease the template 
>> cost that will just improve performance across the board. Maybe that 
>> needs a new frontend compiler, I don't know.
> 
> Phobos2 needs to take a hard look at all the template forwarding going on.
> 
> I've also noticed that many templates can be replaced with 2 or 3 
> ordinary function overloads.
> 

Sure, you can look at this as "templates are bad, we shouldn't use them 
as much", but I see it more of a problem that "templates are bad, we 
should make them less bad". I am also a firm believer that running 
ordinary functions instead of templates can be much easier to write, 
easier to debug, and maybe easier to optimize with a new CTFE engine. 
Perhaps it *is* just a case of using the wrong tool for the job. But 
let's also see if there's anything we can do about template performance 
also. And we have to make it more pleasant to use such things (type 
functions would be nice to have).

I did a test on something I was working on for my talk, and I'm going to 
write a blog post about it, because I'm kind of stunned at the results. 
But in essence, the template `ReturnType!fun` adds 60KB permanently to 
the RAM usage of the compiler, even if the function is just a temporary 
lambda used to check a constraint, and it adds a non-significant amount 
of compile time vs. just `is(typeof(fun()) T)`. The compile time 
difference is hard to measure though, let's say it's 500µs.

I think we need to start picking apart how these things are being 
processed in the compiler, and realize that while it doesn't add *that* 
much, all those little 60kb and 500µs add up when you are generating 
significant tonnage of templates and CTFE.

D's *core strength* is compile-time metaprogramming and code generation. 
It shouldn't also be the thing that drives you away because of compile 
times and memory usage. In other words, we shouldn't have to say "oh you 
did it wrong because you used too much of D's cool unique features".

Maybe I'm wrong, maybe we just have to tell people not to use these 
things. But then they really shouldn't be in phobos...

-Steve

P.S., when I say "we" should make them better, I'm shamefully aware that 
I am too ignorant to be part of that we, it's like the compiler devs are 
my sports team and I refer to them and me as "we" like I'm on the team! 
I appreciate all you guys do!


More information about the Digitalmars-d mailing list