Reuse the search tree between moves #1

Merged
claude merged 1 commits from tree-reuse into main 2026-11-15 03:15:33 +01:00
Collaborator

When the new position continues the previous game, the node for it is looked up in the old tree by matching the keys of the positions played since, and becomes the new root. Its subtree is packed to the front of the node arena in place. Child blocks are always allocated after their parent's block, so moving the kept blocks in their original order only moves them towards the front, and no extra memory is needed.

A root that was a draw inside the old tree (repetition, 50 moves) or was never expanded starts afresh. ucinewgame and Hash changes drop the tree.

SPRT

https://bench.rektdie.com/test/5282/

Elo   | 162.54 +- 22.80 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.13 (-2.94, 2.94) [0.00, 5.00]
Games | N: 472 W: 238 L: 32 D: 202

Correctness

Built with -DRIGBY_VERIFY_TREE, the engine checks the whole tree before and after every reuse: legal moves, and at least one visit more than its children on every expanded node. Over 3600 such checks in self-play driven over UCI found no inconsistency, with 16 MB and 1 MB Hash (full trees included). Driven positions included ucinewgame, the same position searched twice, and fen ... moves continuations.

Bench: 546127 (unchanged: the bench positions are unrelated, nothing to reuse)

🤖 Generated with Claude Code

When the new position continues the previous game, the node for it is looked up in the old tree by matching the keys of the positions played since, and becomes the new root. Its subtree is packed to the front of the node arena in place. Child blocks are always allocated after their parent's block, so moving the kept blocks in their original order only moves them towards the front, and no extra memory is needed. A root that was a draw inside the old tree (repetition, 50 moves) or was never expanded starts afresh. `ucinewgame` and Hash changes drop the tree. ## SPRT https://bench.rektdie.com/test/5282/ ``` Elo | 162.54 +- 22.80 (95%) SPRT | 8.0+0.08s Threads=1 Hash=64MB LLR | 3.13 (-2.94, 2.94) [0.00, 5.00] Games | N: 472 W: 238 L: 32 D: 202 ``` ## Correctness Built with `-DRIGBY_VERIFY_TREE`, the engine checks the whole tree before and after every reuse: legal moves, and at least one visit more than its children on every expanded node. Over 3600 such checks in self-play driven over UCI found no inconsistency, with 16 MB and 1 MB Hash (full trees included). Driven positions included `ucinewgame`, the same position searched twice, and `fen ... moves` continuations. Bench: 546127 (unchanged: the bench positions are unrelated, nothing to reuse) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude added 1 commit 2026-11-15 03:15:26 +01:00
When the new position continues the previous game, find its node in the
old tree (matching the keys of the positions played since) and make it
the root. Its subtree is packed to the front of the arena in place: child
blocks are always allocated after their parent's, so moving the kept
blocks in their original order only moves them towards the front.

A root that was a draw inside the old tree (repetition, 50 moves) or was
never expanded starts afresh. ucinewgame and Hash changes drop the tree.

Built with -DRIGBY_VERIFY_TREE, the engine checks every tree before and
after reuse (legal moves, visit counts); 2900+ such checks over self-play
games, with 16 MB and 1 MB hash, found no inconsistency.

Bench: 546127

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude merged commit 241ad4a546 into main 2026-11-15 03:15:33 +01:00
claude deleted branch tree-reuse 2026-11-15 03:15:34 +01:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: rektdie/Rigby#1