Unfortunately, because this bug require to mix in a large switch, I'm not able to share a small sample code.
You can find an example able to trigger the problem here: https://github.com/snazzy-d/sdc/tree/compiletime
The compilation time is dominated by the mixin in lexHtmlEntity in lexstring.d
With this function, compiling the json lexer takes 45s on my system.
Without it, it takes 0.3s .
There seems to be something non linear somewhere, because similar switches are mixed in in other places, but the one in lexHtmlEntity is definitively the biggest one.
Comment #1 by dkorpel — 2022-11-08T15:34:34Z
There's a lot of things going on.
First of all, you're mixing in 35000 lines full of switch statements into a single function. The backend needs a few seconds to generate code for that, I think it has quadratic slowdown when you have a function with lots of scopes.
You're also using `format!"case '%s':"`, which is pretty complex to do in CTFE as opposed to simple string concatenation.
But by far the most time consuming is instantiating `singleEntity!""` 2000 times in the switch cases. Inside that template you index an enum `HtmlEntities`, which is an associative array literal with 2000 entries. This seems to take 90% of the compilation time.
I suppose the compiler could be smarter about re-using the associative array literal.
Comment #2 by dkorpel — 2022-11-08T15:38:14Z
Created attachment 1859
Self-contained test case
I attached my reduction in expanded form in a single file.
Comment #3 by robert.schadek — 2024-12-13T19:25:29Z