File size: 1,425 Bytes
3c88a0f
 
 
 
1
2
3
4
5
{"type": "session", "harness": "opencode", "id": "chess-0109", "name": "Stockfish Transposition Table"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer."}}
{"type": "message", "message": {"role": "user", "content": "How does Stockfish's transposition table work?"}}
{"type": "message", "message": {"role": "assistant", "content": "Stockfish's TT is a lock-free hash table shared across all threads.\n\nTTEntry (10 bytes): key16, depth8, genBound8, move16, value16, eval16\nTTCluster (32 bytes): 3 entries + 2 bytes padding, cache-line aligned\n\nprobe(key): Returns (hit, TTData, TTWriter). Uses 16-bit key verification.\nresize(mbSize): Allocates with large pages (2MB Linux via MADV_HUGEPAGE, MEM_LARGE_PAGES Windows).\nclear(): Multi-threaded parallel zeroing.\nnew_search(): Increments generation counter for age-based eviction.\n\nDesign principles:\n- Racy access via RelaxedAtomic - accepts occasional stale reads for speed\n- Legal move validation in search after using TT moves\n- Generation-based aging (5-bit genBound) prevents stale entries from persisting\n- 10-byte entries maximize information density per cache line\n\nWhy lock-free works: Search already handles stale data gracefully. A slightly wrong TT move just means the position gets re-searched. The performance gain from avoiding mutexes vastly outweighs the cost of occasional redundant work."}}