Slow code, slow

Rubn where at is.this
Fri Feb 23 20:51:20 UTC 2018


On Friday, 23 February 2018 at 20:41:17 UTC, bauss wrote:
> On Friday, 23 February 2018 at 20:35:44 UTC, Rubn wrote:
>> On Friday, 23 February 2018 at 20:15:12 UTC, H. S. Teoh wrote:
>>> Now that I got your attention:
>>>
>>> 	https://issues.dlang.org/show_bug.cgi?id=18511
>>>
>>> tl;dr: A trivial piece of code, written as ostensibly 
>>> "idiomatic D" with std.algorithm and std.range templates, 
>>> compiles *an order of magnitude* slower than the equivalent 
>>> hand-written loop.  The way the compiler compiles templates 
>>> needs some serious improvement.
>>>
>>> (And this is why our current fast-fast-fast slogan annoys me 
>>> so much. One can argue that it's misleading advertising, 
>>> given that what's considered "idiomatic D", using features 
>>> like templates and generic code that's highly-touted as D's 
>>> strong points, compiles a whole order of magnitude slower 
>>> than C-style D.  Makes me cringe every time I hear "fast 
>>> code, fast". Our old slogan is a much more accurate 
>>> description of the current state of things.)
>>>
>>>
>>> T
>>
>> It's not that big of a slow down. Using "fast" you don't 
>> import any modules so they never have to be parsed. That's 
>> pretty much all of phobos you don't have to parse in that 
>> example. That's just the initial cost too. In a big project 
>> this won't make a difference. You create a tiny example that 
>> is irrelevant to the larger scale, that takes 0.3 seconds 
>> longer to compile. It's a magnitude slower cause in your fast 
>> example it's literately only parsing 5 lines of code instead 
>> of hundreds of lines like it is in your slow example.
>
> I disagree.
>
> It actually matters a lot for big projects with lots of 
> templates, especially nested templates. Gets a whole lot worse 
> when it's templates within mixin templates with templates.
>
> It's not just a "0.3" second difference, but can be half a 
> minute or even more.

Like with anything, since you can now basically run code at 
compile time, you are going to have to make optimizations to your 
code. If you make a million template instances, well a compiler 
isn't going to magically be able to make that fast. This slowdown 
for this specific example isn't cause by templates, it's caused 
by having to parse all the extra lines of code from phobos. I 
didn't say there aren't problems with templates, but this example 
accurately depicts nothing.


More information about the Digitalmars-d mailing list