[SAOC 2026] DMD CTFE Performance Weekly Update #6

Hipreme msnmancini at hotmail.com
Wed Nov 25 21:16:07 UTC 2026


On Monday, 16 November 2026 at 16:56:53 UTC, Abul Hossain Khan 
wrote:
> Hi everyone,
>
> This one covers the last week and a half.
>
> #### The design doc
>
> The design doc for the CTFE interface is done.
>
> In short: an engine gets a whole top-level call (the function 
> and its arguments) and gives back the result, or says no and 
> the AST interpreter runs it like today. `ctfeInterpret` and its 
> call sites don't change. Values cross as `Expression`, and the 
> doc writes down which node each type comes as.
>
> Stefan and Dennis both reviewed it. Stefan pointed out that the 
> ABI should be documented, so I added that. One thing that came 
> out of both reviews is that we need to get rid of semantic 
> during CTFE. That is a hard job though, so it is for later.
>
> #### First Step
>
> https://github.com/dlang/dmd/pull/24365
>
> #### CTFE bug fixes
>
>
> - https://github.com/dlang/dmd/pull/24217
> - https://github.com/dlang/dmd/pull/24230
> - https://github.com/dlang/dmd/pull/24246
> - https://github.com/dlang/dmd/pull/24248
> - and cauple of more
>
>
> #### What's next
>
> - The hook for top-level calls, with a small test engine.
> - The rest of the bug list on the side.
>
> Thanks to Dennis and Stefan for the reviews. As always, feel 
> free to leave any feedback or suggestions!



Hey nice work so far! I would love to see if you have a CTFE 
benchmark happening there.
There are some suggestions from me:


1. Having test cases where the CTFE performance is improving and 
where you're tackling on
2. Having history of the result of your CTFE improvement
3. Having CTFE situations which didn't work before your work on 
that

All of them in a single place, a folder or something can give you 
great visibility for both you and the work you're doing. We've 
got recently a performance regression tester and using it for 
showing the improvements on the memory usage, compiling speed and 
even stupid examples on where the CTFE can take lots of time, 
like O(n³), O(n²) are good test cases when you get a performance 
improvement:


```d

import std.stdio;

ulong fibonacci(ulong n)
{
     if (n <= 1)
         return n;

     return fibonacci(n - 1) + fibonacci(n - 2);
}

enum result = fibonacci(40);

void main()
{
     writeln(result);
}

```

Take a look at that. On an AMD Ryzen 9 9900X, this takes 70 
seconds which is fairly unusable. I know this is a very slow 
algorithm, but what I'm mentioning, what if you could take it 
down to 35 seconds? In runtime on run.dlang, this algo runs in 
460ms in runtime with DMD. In javascript, this takes 570ms. I 
don't expect this to get anywhere close,but at least not being 
100x slower would make a lot of difference :)


More information about the Digitalmars-d mailing list