-
Notifications
You must be signed in to change notification settings - Fork 4
[1/6] Improve PSQT evaluation performance #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
bca3f3e to
d7df55a
Compare
Performance optimizations for board evaluation: - Use Zobrist hash instead of FEN string for cache keys (faster hashing) - Add cache size limit (1M entries) to prevent unbounded memory growth - Optimize board_evaluation() to iterate over pieces instead of all 64 squares - Typically 16-32 pieces vs always 64 squares - Reduces unnecessary iterations by ~50-75% These changes improve evaluation speed without affecting correctness. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
d7df55a to
e21928a
Compare
🔬 Stockfish Benchmark Resultsvs Stockfish Skill Level 3
Non-checkmate endings:
vs Stockfish Skill Level 4
Non-checkmate endings:
vs Stockfish Skill Level 5
Non-checkmate endings:
Configuration
|
Greptile OverviewGreptile SummaryThis PR optimizes the board evaluation performance through three key improvements:
The changes are well-implemented and maintain evaluation correctness. The optimizations reduce computational overhead without altering search behavior. The cache eviction strategy is simple but effective for preventing unbounded memory growth during extended searches. Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| moonfish/psqt.py | Optimized evaluation caching with Zobrist hashing and piece iteration; no logical issues found |
Sequence Diagram
sequenceDiagram
participant Engine as Alpha-Beta Engine
participant Cache as board_evaluation_cache
participant Eval as board_evaluation
participant Board as chess.Board
Engine->>Cache: call board_evaluation(board)
Cache->>Board: zobrist_hash(board)
Board-->>Cache: int hash key
alt Cache hit
Cache-->>Engine: return cached value
else Cache miss
alt Cache full (≥1M entries)
Cache->>Cache: clear entire cache
end
Cache->>Eval: call board_evaluation(board)
Eval->>Eval: get_phase(board)
loop For each piece type
Eval->>Board: pieces(piece_type, WHITE)
Board-->>Eval: SquareSet of white pieces
loop For each white piece
Eval->>Eval: mg_white += table[square^56] + value
Eval->>Eval: eg_white += table[square^56] + value
end
Eval->>Board: pieces(piece_type, BLACK)
Board-->>Eval: SquareSet of black pieces
loop For each black piece
Eval->>Eval: mg_black += table[square] + value
Eval->>Eval: eg_black += table[square] + value
end
end
Eval->>Eval: calculate tapered eval based on phase
Eval-->>Cache: evaluation score
Cache->>Cache: store in cache[hash]
Cache-->>Engine: return evaluation score
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, no comments
Summary
board_evaluation()to iterate over actual pieces (~16-32) instead of all 64 squaresDetails
The board evaluation function is called frequently during search. These optimizations reduce overhead:
chess.polyglot.zobrist_hash()returns an integer, which is faster to hash and compare than FEN stringsboard.pieces(piece_type, color)returns only occupied squares, reducing iterations by 50-75%Test plan
🤖 Generated with Claude Code