feat(search): shared transposition table + Lazy SMP - #8
Merged
Merged
Conversation
Add a fixed-size, power-of-two transposition table keyed by the Zobrist hash dragontoothmg maintains incrementally (Board.Hash). Each 16-byte slot is a pair of atomic.Uint64 words accessed with Hyatt's lockless XOR trick, so it is safe for concurrent use with no mutex. Entries store the best move plus an EXACT / LOWER / UPPER bound; mate scores are rebased by ply on store and probe. negamax now probes the table for a cut-off and stores its result, and the stored move is ordered first in orderMoves even when the entry is too shallow to cut. This alone drops a depth-8 search from the opening from ~30s to ~1.3s single-threaded. Add Lazy SMP: SearchParams.Threads workers run iterative deepening in parallel on private board copies over the one shared table, seeded at staggered start depths so they diverge; the deepest completed result wins. The UCI layer owns a persistent engine.TT (sized by the new Hash option, cleared on ucinewgame) and honours a new Threads option, capped at the machine's core count. Docs (README, architecture, design, engine-strength, performance) updated to match. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two search features from the roadmap, both leaning on the Zobrist hash
dragontoothmgalready exposes (Board.Hash()):Transposition table (
internal/engine/transposition.go)Hashoption (default 64 MiB).atomic.Uint64words accessed with Hyatt's lockless XOR trick (word0 = key ^ data) — safe for concurrent Lazy-SMP access with no mutex; a write torn across goroutines simply reads as a miss.datapacks best move, an int32 score, depth, and an EXACT / LOWER / UPPER bound flag.negamaxprobes for a cut-off and stores its result with the correct bound; the stored move is ordered first inorderMoveseven when the entry is too shallow to cut.Lazy SMP (
internal/engine/search.go)SearchParams.Threadsworkers run iterative deepening in parallel, each on its own copy of the board (dragontoothmg.Boardis all value types), over the one shared table.engine.TT(cleared onucinewgame) and honours a newThreadsoption, capped atruntime.NumCPU()at search time.Modelled on the same design in pyChess (
lazy_smp.py/shared_tt.py), adapted to Go's shared-memory goroutines instead ofmultiprocessing.Impact (Apple M4, depth from the opening)
Basic Lazy SMP (no root-move splitting yet) adds parallel breadth and tactical robustness; fixed-depth wall-clock is roughly flat pending root splitting, which is noted in the roadmap and docs.
Tests
transposition_test.go— bound/window semantics, depth-preferring replacement, ply rebasing round-trip, and a-raceconcurrent-access test.search_test.go— TT does not change the best move, warm TT cuts node count, and the Lazy-SMP path finds mate / wins material / respectsmovetime.go test -race ./...,golangci-lint(v2.13.2),govulncheck,gofumptall clean.🤖 Generated with Claude Code