feat: collect the tree when the node arena is full

With tree reuse the arena fills up quickly: at 8+0.08 with Hash=64 it
was full on 19 of 30 moves of a self-play game. A full tree could not
expand anything any more, it only re-evaluated 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), 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.

A collection of a full 64 MB tree (3.3M nodes) takes about 21 ms and
keeps about 40%. The -DRIGBY_VERIFY_TREE build checks the tree after
every collection: 3200+ checks in self-play with 1 MB and 16 MB Hash,
no inconsistency.

Bench: 546127

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rektdieandclaude committed 2026-11-15 03:19:28 +01:00
1 parent 241ad4a546
commit 3dc4e6c136
3 files changed
+73 -8

No files matched your search

+3
View File
@@ -18,6 +18,9 @@ Every change is validated with SPRT on OpenBench.
heuristics (captures, promotions, checks, pawn threats) for the policy.
- Tree reuse between moves: the subtree of the new position is packed to the
front of the node arena in place, so it costs no extra memory.
- When the arena is full, the least visited parts of the tree are cut back to
leaves (keeping their visits and Q) and the rest is packed, so search never
stops expanding.
- Single-threaded.
## Building