Summary: Very slow compilation for large switch() using -O and
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from Ben Eirich <> 2011-09-10 09:07:24 PDT ---
Created an attachment (id=1023)
Test case

I am attempting to port some CPU emulators from C# to D. It uses a large
central switch statement (2221 lines in this case) with a case per opcode; the
contents of each opcode handler are 'manually inlined' because in C# the
automatic inliner is not very aggressive and there is no explicit inline
modifier (same as in D).

Building the attached program takes under 1 second with only -inline, about 4-5
seconds with only -O, and around 15 minutes with -O and -inline. -release
changes outcomes slightly but not in a significant way.

Because of the nature of this issue, it was not possible to reduce this to a
smaller test case. It is not the number of case statements in the switch that
cause this issue, it is the size or complexity of the code inside the switch

It's very possible the issue is simply related to very large methods rather
than anything at all to do with switch.

The resulting EXE does work and -O -inline is about 17% faster than -O alone
when run in a benchmark. It just takes a very long time to build.

This isn't a total blocker, however, this is only one CPU and I have about 6-7
I would like to port immediately, and long term, maybe around a dozen. The Z80
CPU has a switch statement which is about 4x bigger than this.

As I am very new to the D toolchain, I'm not currently using incremental
builds. I assuming this is possible and it should mitigate the problem
somewhat. It does make performance testing and optimization an issue, though. I
am using DMD 2.054.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to