Why does this mixin fail to compile?
Steven Schveighoffer
schveiguy at gmail.com
Wed Jul 3 14:58:51 UTC 2024
On Wednesday, 3 July 2024 at 11:57:58 UTC, Lance Bachmeier wrote:
> On Wednesday, 3 July 2024 at 03:52:41 UTC, Steven Schveighoffer
> wrote:
>> And yes, it is faster to do this than appending. But you have
>> to do a *lot* of it to make a huge difference.
>
> What about creating an array of strings and then using join?
> One obvious problem with this solution is the requirement to
> specify the size of `buffer`.
It's important to remember that what happens at CTFE is not the
same as what happens at runtime. CTFE is a tree-walking
interpreter, and does weird things like allocate storage when you
change a value. And there is no optimization.
So the best thing to do is try it and see what happens. You can't
use your knowledge of how code compiles to judge CTFE performance.
My general feel is that the more code you give to the CTFE
interpreter, the worse it gets. Like, try doing `format` in CTFE
vs. simple appending it will be vastly different.
-Steve
More information about the Digitalmars-d-learn
mailing list