Sometimes 100 lines of code can fix your ctfe perf

Stefan Koch uplink.coder at googlemail.com
Tue Aug 24 16:25:35 UTC 2021


On Tuesday, 24 August 2021 at 16:16:50 UTC, Per Nordlöw wrote:
> On Tuesday, 24 August 2021 at 14:07:45 UTC, Stefan Koch wrote:
>> Good Morning,
>
> Would it be motivated to have the compiler deduce that `result 
> ~= "whatever"` can be lowered to a reallocating append because 
> `result` isn't aliased:
>
> ```d
> enum x = () { string result;
> foreach(_; 0 ..n_iterations)
>   result ~= "whatever"
> return result; } ()
> ```

Of course you could try to recognize certain patterns and treat 
them specially,
but that complicates the compiler and now your compile time 
performance is dependent on a bunch of heuristics, which in my 
experience have a habit of failing in the most inconvenient ways 
and situations.


More information about the Digitalmars-d mailing list