200-600x slower Dlang performance with nested foreach loop

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Jan 26 18:22:59 UTC 2021


On Tue, Jan 26, 2021 at 06:13:54PM +0000, methonash via Digitalmars-d-learn wrote:
[...]
> I cannot post the full source code.

Then we are limited in how much we can help you.


> Regarding a reduced version reproducing the issue: well, that's
> exactly what the nested foreach loop does. Without it, the program
> reaches that point quickly.

By "reduced version" we mean a code exceprt that's (1) compilable, (2)
runnable, and (3) exhibits the same problem that you're seeing in your
full code.

Posting an isolated loop cut out of some unknown function in some
unknown module somewhere is not helping us identify where your problem
is.


> With the nested foreach block, it slows to a crawl. More specifically,
> commenting-out the indexOf() or countUntil() sub-blocks preserves fast
> performance, but I'm not sure if that may be related to compiler
> optimizations realizing that there's nothing but "dead/nonexistent
> code" inside the loops and generating a binary that just never goes
> there.

When in doubt, use a disassembler to see exactly what is the generated
code.


> If this may help: I've composed the second Dlang implementation as one
> extended block of code within main() and am thinking of soon
> refactoring the code into different functions. I remain pessimistic of
> whether this may help.

As I said in my other reply: don't guess, profile!  Randomly changing
your code in the hopes that it will help, in general, won't.


> Is there any possibility this could be GC-related?

Without more information and a complete, compilable example, it's
anybody's guess.


T

-- 
Debian GNU/Linux: Cray on your desktop.


More information about the Digitalmars-d-learn mailing list