lynx-chess / Lynx

Chess Engine, written in C#
https://lichess.org/@/Lynx_BOT
MIT License
47 stars 4 forks source link

🧠 Cache `Move.UCIString` results in a `Dictionary` #1001

Closed eduherminio closed 1 month ago

eduherminio commented 2 months ago

Frist attempted in https://github.com/lynx-chess/Lynx/pull/997 with a concurrent dictionary, After #999, we can guarantee the Move.UCIString() calls related to info commands to happen in a single thread, so we can re-try with a regular dictionary. We also move here the serialization of bestmove command to the Writer thread to be able to do the same with UCIString() invocations there.

bench 14 comparisons (it should be more drastic in real games, where all positions are related to each other) show 50% less string allocations

Before:

main-precache

This branch:

cache

Together with #1002

Test  | perf/stringbuilder-pool
Elo   | 1.30 +- 3.59 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=32MB
LLR   | 2.95 (-2.25, 2.89) [-5.00, 0.00]
Games | 16004: +4511 -4451 =7042
Penta | [425, 1828, 3428, 1904, 417]
https://openbench.lynx-chess.com/test/711/