lichess-org / scalachess

Chess API written in scala. Immutable and free of side effects.
https://lichess.org
MIT License
667 stars 206 forks source link

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

Closed lenguyenthanh closed 1 year ago

lenguyenthanh commented 1 year ago

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.

ornicar commented 1 year ago

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

cIfHO00

lenguyenthanh commented 1 year ago

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.

lenguyenthanh commented 1 year ago

close with #449