Skip to content

Conversation

@luccabb
Copy link
Owner

@luccabb luccabb commented Jan 20, 2026

Summary

  • Use Zobrist hash instead of FEN string for evaluation cache keys (faster integer hashing vs string comparison)
  • Add cache size limit (1M entries) to prevent unbounded memory growth during long searches
  • Optimize board_evaluation() to iterate over actual pieces (~16-32) instead of all 64 squares

Details

The board evaluation function is called frequently during search. These optimizations reduce overhead:

  1. Zobrist hashing: chess.polyglot.zobrist_hash() returns an integer, which is faster to hash and compare than FEN strings
  2. Cache eviction: Simple clear-on-full policy prevents memory exhaustion in long games
  3. Piece iteration: Using board.pieces(piece_type, color) returns only occupied squares, reducing iterations by 50-75%

Test plan

  • All 64 unit tests pass
  • No changes to search behavior, only evaluation speed

🤖 Generated with Claude Code

@luccabb luccabb force-pushed the feature/psqt-evaluation-performance branch from bca3f3e to d7df55a Compare January 21, 2026 06:43
@luccabb luccabb changed the title [1/9] Improve PSQT evaluation performance [1/7] Improve PSQT evaluation performance Jan 21, 2026
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>
@luccabb luccabb force-pushed the feature/psqt-evaluation-performance branch from d7df55a to e21928a Compare January 21, 2026 07:33
@luccabb luccabb changed the title [1/7] Improve PSQT evaluation performance [1/6] Improve PSQT evaluation performance Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants