Answers.Body: <p>If your goal is to get the highest quality of analysis, then the short answer is "never".</p>
  
  <p>The reason is that if you analyze similar positions within a game, then the existing hash table entries can still be valuable for move ordering and evaluation, because the same positions might be encountered somewhere in the search tree again.</p>
  
  <p>If you switch to a new game, then the hash should be cleared, but in that case Stockfish already does it implicitly when it receives the <code>ucinewgame</code> command. In fact, in Stockfish <a href="https://github.com/official-stockfish/Stockfish/blob/80d59eea392fc073f6d0ba29cb9a97e3d705ee58/src/uci.cpp#L229" rel="nofollow noreferrer"><code>ucinewgame</code></a> does exactly the same as <a href="https://github.com/official-stockfish/Stockfish/blob/80d59eea392fc073f6d0ba29cb9a97e3d705ee58/src/ucioption.cpp#L40" rel="nofollow noreferrer"><code>setoption name Clear Hash</code></a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-14T08:07:45.080Z
Answers.LastActivityDate: 2019-10-14T08:07:45.080Z
Answers.UserDisplayName: Fabian Fichter
Answers.Body: <p>A hash table is used to store evaluations/information for a position, so that evaluating it later is either instantaneous or much more efficient. If you let your engine think on a certain position for a while, the positions it thinks of when searching ahead are stored in its table. This is useful when you make a move on the current position and reach a new position for Stockfish to analyse (since its already "seen" it in its analysis).</p>
  
  <p>So when analyzing a certain game, do not reset the hash table. You could reset it when moving on to a new game though, especially if the new game starts off with different opening moves than the previous game. This is because most/all of the positions analysed in the previous game will be irrelevant, and will just take up space in the hash table.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-09-19T03:46:03.477Z
Answers.Text: The hash table should be cleared when performing benchmarks, so previous tests do not affect future tests?
Answers.UserDisplayName: qwr
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-09-19T08:10:59.523Z
Answers.Text: @qwr I think that depends. E.g., if you're benchmarking individual moves, then clearing and initializing the hash table on each move could take up a chunk of the measured time. But if each run of your test is fairly long, then resetting the TT makes sense (although even then Stockfish should, on its own, get rid of data it no longer needs in the TT quite fast).
Answers.UserDisplayName: Inertial Ignorance
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-16T06:21:42.977Z
Answers.LastActivityDate: 2019-10-16T06:21:42.977Z
Answers.UserDisplayName: Inertial Ignorance
Body: <p>I am developing a program that analyzes games sequentially, i.e. one game after another.</p>
  
  <p>Below are the parameters.</p>
  
  <hr>
  
  <p>Engine: Stockfish 10</p>
  
  <p>Threads: 2</p>
  
  <p>Hash Table: 4000</p>
  
  <p>Depth: 30</p>
  
  <hr>
  
  <p>My question is about when to use the command: "setoption name Clear Hash."</p>
  
  <p>Should it be used after each position is analysed? This means that each position would have a "fresh" hash at the beginning of the analysis.</p>
  
  <p>Or should it be used after each game is analysed? What are the differences?</p>
  
Tags: <stockfish><programming><computer-chess><uci>
Title: When to use Clear Hash
ThreadText: # When to use Clear Hash
  
  (Asked by: username_0 on 2019-10-14)
  
  I am developing a program that analyzes games sequentially, i.e. one game after another.
  
  Below are the parameters.
  
  ---
  
  Engine: Stockfish 10
  
  Threads: 2
  
  Hash Table: 4000
  
  Depth: 30
  
  ---
  
  My question is about when to use the command: "setoption name Clear Hash."
  
  Should it be used after each position is analysed? This means that each position would have a "fresh" hash at the beginning of the analysis.
  
  Or should it be used after each game is analysed? What are the differences?
  
  **Tags:** stockfish, programming, computer-chess, uci
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-10-14. Score: 4 | Accepted answer
  
  If your goal is to get the highest quality of analysis, then the short answer is "never".
  
  The reason is that if you analyze similar positions within a game, then the existing hash table entries can still be valuable for move ordering and evaluation, because the same positions might be encountered somewhere in the search tree again.
  
  If you switch to a new game, then the hash should be cleared, but in that case Stockfish already does it implicitly when it receives the `ucinewgame` command. In fact, in Stockfish [`ucinewgame`](https://github.com/official-stockfish/Stockfish/blob/80d59eea392fc073f6d0ba29cb9a97e3d705ee58/src/uci.cpp#L229) does exactly the same as [`setoption name Clear Hash`](https://github.com/official-stockfish/Stockfish/blob/80d59eea392fc073f6d0ba29cb9a97e3d705ee58/src/ucioption.cpp#L40).
  
  
  ---
  
  ### Answer by username_2 on 2019-10-16. Score: 1
  
  A hash table is used to store evaluations/information for a position, so that evaluating it later is either instantaneous or much more efficient. If you let your engine think on a certain position for a while, the positions it thinks of when searching ahead are stored in its table. This is useful when you make a move on the current position and reach a new position for Stockfish to analyse (since its already "seen" it in its analysis).
  
  So when analyzing a certain game, do not reset the hash table. You could reset it when moving on to a new game though, especially if the new game starts off with different opening moves than the previous game. This is because most/all of the positions analysed in the previous game will be irrelevant, and will just take up space in the hash table.
  
  > **Comments:**
  > **username_3**: The hash table should be cleared when performing benchmarks, so previous tests do not affect future tests?  
  > **username_2**: @username_3 I think that depends. E.g., if you're benchmarking individual moves, then clearing and initializing the hash table on each move could take up a chunk of the measured time. But if each run of your test is fairly long, then resetting the TT makes sense (although even then Stockfish should, on its own, get rid of data it no longer needs in the TT quite fast).  
  
  ---
  
  