Thread overview
[Issue 23464] Pathological compilation slowdown when mixin in large switches
Nov 05, 2022
deadalnix
Nov 06, 2022
Ketmar Dark
Nov 08, 2022
Adam D. Ruppe
Nov 08, 2022
Dennis
Nov 08, 2022
Dennis
Dec 17, 2022
Iain Buclaw
Jan 04, 2023
deadalnix
November 05, 2022
https://issues.dlang.org/show_bug.cgi?id=23464

deadalnix <deadalnix@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |21121


Referenced Issues:

https://issues.dlang.org/show_bug.cgi?id=21121
[Issue 21121] Optimizer slowdowns
--
November 06, 2022
https://issues.dlang.org/show_bug.cgi?id=23464

Ketmar Dark <ketmar@ketmar.no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar@ketmar.no-ip.org

--
November 08, 2022
https://issues.dlang.org/show_bug.cgi?id=23464

Adam D. Ruppe <destructionator@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |destructionator@gmail.com

--
November 08, 2022
https://issues.dlang.org/show_bug.cgi?id=23464

Dennis <dkorpel@live.nl> changed:

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

--- Comment #1 from Dennis <dkorpel@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.

--
November 08, 2022
https://issues.dlang.org/show_bug.cgi?id=23464

--- Comment #2 from Dennis <dkorpel@live.nl> ---
Created attachment 1859
  --> https://issues.dlang.org/attachment.cgi?id=1859&action=edit
Self-contained test case

I attached my reduction in expanded form in a single file.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=23464

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--
January 04, 2023
https://issues.dlang.org/show_bug.cgi?id=23464

deadalnix <deadalnix@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=21121

--