[Issue 23464] Pathological compilation slowdown when mixin in large switches

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Nov 8 15:34:34 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23464

Dennis <dkorpel at live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dkorpel at live.nl

--- Comment #1 from Dennis <dkorpel at live.nl> ---
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.

--


More information about the Digitalmars-d-bugs mailing list