Collect the tree when the node arena is full #4

Merged
claude merged 1 commits from tree-gc-nn into main 2026-11-15 11:56:37 +01:00
Collaborator

When an allocation fails, the tree is collected right after the playout. The children of every node below a visit threshold are dropped (the node keeps its visits and Q, becomes a leaf again and is expanded anew on its next visit), and the rest is packed in place with the same block compaction as tree reuse. The threshold is the smallest one that brings the tree down to half the arena; visits only shrink going down, so one pass over the tree gives the size kept for every threshold.

  • Motivation: in a 240-move self-play diagnostic of main at 8+0.08 with Hash=64, the reused subtree alone was often 3.0-3.3M of the 3.35M nodes, and the tree was full on 90 moves (37%). A full tree could not expand anything for the rest of the move, it only re-evaluated leaves.
  • With this change: the tree was collected on 27 of 158 moves, once each, and search kept expanding afterwards. A collection of a full 64 MB tree costs about 20-30 ms.
  • Rebased from the earlier tree-gc branch onto main with the value network and second-visit expansion.

SPRT

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

Elo   | 8.74 +- 6.47 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.00 (-2.94, 2.94) [0.00, 10.00]
Games | N: 3262 W: 996 L: 914 D: 1352
Penta | [48, 226, 1023, 264, 70]

Correctness

  • The -DRIGBY_VERIFY_TREE build verifies the tree after every collection: UCI-driven self-play passed 700 checks / 428 collections with 1 MB Hash and 476 checks / 205 collections with 16 MB, including repeated searches of the same position and a root at halfmove 99.
  • uci, go wtime/nodes/infinite, stop and quit work.
  • The bench is deterministic and unchanged, because the bench never fills the tree.

Bench: 546018

🤖 Generated with Claude Code

When an allocation fails, the tree is collected right after the playout. The children of every node below a visit threshold are dropped (the node keeps its visits and Q, becomes a leaf again and is expanded anew on its next visit), and the rest is packed in place with the same block compaction as tree reuse. The threshold is the smallest one that brings the tree down to half the arena; visits only shrink going down, so one pass over the tree gives the size kept for every threshold. - **Motivation:** in a 240-move self-play diagnostic of `main` at 8+0.08 with Hash=64, the reused subtree alone was often 3.0-3.3M of the 3.35M nodes, and the tree was full on 90 moves (37%). A full tree could not expand anything for the rest of the move, it only re-evaluated leaves. - **With this change:** the tree was collected on 27 of 158 moves, once each, and search kept expanding afterwards. A collection of a full 64 MB tree costs about 20-30 ms. - Rebased from the earlier `tree-gc` branch onto `main` with the value network and second-visit expansion. ## SPRT https://bench.rektdie.com/test/5286/ ``` Elo | 8.74 +- 6.47 (95%) SPRT | 8.0+0.08s Threads=1 Hash=64MB LLR | 3.00 (-2.94, 2.94) [0.00, 10.00] Games | N: 3262 W: 996 L: 914 D: 1352 Penta | [48, 226, 1023, 264, 70] ``` ## Correctness - The `-DRIGBY_VERIFY_TREE` build verifies the tree after every collection: UCI-driven self-play passed 700 checks / 428 collections with 1 MB Hash and 476 checks / 205 collections with 16 MB, including repeated searches of the same position and a root at halfmove 99. - `uci`, `go wtime/nodes/infinite`, `stop` and `quit` work. - The bench is deterministic and unchanged, because the bench never fills the tree. Bench: 546018 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude added 1 commit 2026-11-15 11:56:29 +01:00
Tree reuse keeps most of the previous tree, so the arena fills up fast.
In a 240-move self-play diagnostic of main at 8+0.08 with Hash=64, the
reused subtree alone was often 3.0-3.3M of the 3.35M nodes, and the tree
was full on 90 moves (37%). A full tree cannot expand anything any more;
for the rest of the move it only re-evaluates leaves.

Now a failed allocation triggers a collection after the playout. The
children of every node below a visit threshold are dropped (the node
keeps its visits and Q and becomes a leaf again, expanded anew on its
next visit), and the rest is packed in place with the same block
compaction as tree reuse. The threshold is the smallest one that brings
the tree down to half the arena; visits only shrink going down, so one
pass over the tree gives the size kept for every threshold.

In the same diagnostic with this change the tree was collected on 27 of
158 moves, once each, and search kept expanding afterwards; a collection
of a full 64 MB tree costs about 20-30 ms.

Checked: the -DRIGBY_VERIFY_TREE build verifies the tree after every
collection; UCI-driven self-play passed 700 checks / 428 collections
with 1 MB Hash and 476 checks / 205 collections with 16 MB, including
repeated searches of the same position and a root at halfmove 99.
uci, go wtime/nodes/infinite, stop and quit work. The bench is
unchanged because the bench never fills the tree.

Rebased from the earlier tree-gc branch onto main with the value
network and second-visit expansion.

Bench: 546018

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude merged commit 1754753a6e into main 2026-11-15 11:56:37 +01:00
claude deleted branch tree-gc-nn 2026-11-15 11:56:37 +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#4