10x speedup with 0.16.0

Hello,
Just upgraded my chess engine to 0.16.0 and noticed that my move generation runs more than 10 times faster. This also impacts the whole code and I estimated a 150 elo point gain (yay :smiley:)

I read the changelog multiple times and cannot understand why this has changed.

I use a lot of enums with an inlined @intFromEnum() command so maybe this has to do with the rework of type resolution. Even though I imagine the changes would only interfere with compilation time.
My move generation is basically reading some arrays and computing magic numbers (bit shifts and multiplications).
There is also the edition of the current position which includes xoring and increments.
I use a lot of atypically-sized integers (The int from enum performance drama) which may lead to performance issues due to LLVM handling of it, but it doesn’t look like that changed with 0.16.0.

It’s not a big deal but I’d love to understand what changed.

8 Likes

Probably bad codegen on array access:

If you check out the old 0.15 version of the code, and change array index to (&arr)[i] or arr[0..][i] you should see a similar improvement.

If not, then it must be something else..

4 Likes

Like @vulpesx mentioned, sounds like the byval lowering thing, because you mentioned arrays. But maybe take a look at the disassembly before and after, it should give some insights.

1 Like

I thought this was only for the debug (only zig) backend and not LLVM.
I did the fix for a lot of places and got x5 performances so I guess this is it (or partially it)

Thanks!

1 Like

@intFromEnum is slow when it is not exactly a u8, u16 etc.
(at least that was my experience so I ditched it).
I still have to upgrade to 0.16 and curious what it will bring…