lichess-org / scalachess

Chess API written in scala. Immutable and free of side effects.

Home Page:https://lichess.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Consider if we should stop using `TotalWrapper` for `OpaqueBitboard` for performance gain

lenguyenthanh opened this issue · comments

As demonstrated in #441, we may have a significant gain in performance by switching from Bitboard to Long.

I guess the performance penalty is mostly caused by TotalWrapper because with it, Bitboard is be boxed object , not just a primitive Long anymore.

But maybe the opaque type has some responsibility as well.

do you use this metals command? it might provide some insight

cIfHO00

yes, I started to use that recently and with async-profiler to understand more about what happen under the hood.
Here is one example I got after running bench-marking with async-profiler.
Screenshot 2023-07-09 at 20 53 29

We can see that, just for Bitboard.contains it required much more than what needed.

I guess scalalib.newtypes are over kill for Bitboard

Maybe some inline for Bitboard.contains can help a bit in this case, but I think, we can have a much bigger gain if we migrated Bitboard from scalalib.newtypes.

close with #449