Skip to content

Conversation

@borg323
Copy link
Member

@borg323 borg323 commented Sep 18, 2025

Can be enabled by the FIX_TT build option (on by default).
Introduces a new Hash uci option to control the size of the transposition table in MB (default 50).

@borg323 borg323 requested a review from Menkib64 September 18, 2025 09:25
picked_node.tt_low_node = tt_iter->second.lock();
}
#else
auto entry = search_->tt_->LookupAndPin(picked_node.hash);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could insert nodes here if insertions avoid random slowdowns of the dynamic version. For the testing purposes it is better to delay insert. That makes it easier to compare how the fixed implementation compares to the dynamic implementation.

#ifdef FIX_TT
search_->tt_->Insert(node_to_process.hash,
std::make_unique<std::weak_ptr<LowNode>>(
node_to_process.tt_low_node));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a comment that insertions aren't thread safe if a hash is the same. Current implementation silently ignores insertion if hash is already present in the table.

I was thinking about last inserted eviction policy. It isn't perfect match how search access nodes. We can end up evicting nodes which are old insertion which are still close to the PV line. A better eviction policy would be least recently accessed but that would be expensive to implement without major refactoring.
We could reduce risk of eviction in insertion if garbage collector evicts expired weak pointers. I don't think initial version needs this. It can be an useful change when playing matches against strong engines where both agree on a long line.

The table implementation requires unique_ptr storage. Could we modify storage to support weak_ptr too? I think this is also a change that shouldn't be part of initial version. It could be a future improvement. It could be also redundant work if we choose to give ownership to the hash table to allow cycles in the tree.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the thread safety issue, can you elaborate? The insertion failing shouldn't cause any correctness issues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would mean transposition might have different low node. Search would work but transpositions wouldn't share information which would affect evaluation. It should be simple change to make Insert return the existing value or an inserted value. The caller can then use the returned value which would be known to be shared between all transpositions.
GatherMinibatch found the same transposition from different paths fairly frequently when I was experiment putting TT Insertion into GatherMinibatch.

The cache is not updated if the hash is found, so an expired weak_ptr would
block new insertions until evicted.
@borg323 borg323 marked this pull request as draft September 20, 2025 06:01
@borg323
Copy link
Member Author

borg323 commented Sep 20, 2025

I'm having crashes with the last commit when the TT is small, (e.g. Hash=1). Converted to draft while I investigate.

If insert fails due to the hash already being present, an effort is made to
use the cached one instead.
@Menkib64
Copy link
Contributor

I got an idea which may improve or worsen things. I'm thinking that we should move ownership of LowNode to transposition table eventually. We could already move towards this if TT holds shared_ptr instead of weak_ptr. It might allow reusing a few more transpositions. There are potential issue like increased memory usage, and potential small changes how GC thread works (it might need to run more often). I guess it should be a separate future change because it has unknown performance implications and potential changes to other parts of search implementation.

@borg323
Copy link
Member Author

borg323 commented Oct 23, 2025

This is not a new idea, see 699a40c.

@Menkib64
Copy link
Contributor

I noticed ThinkingInfo includes hashfull. We could report the hash status using it. That could give more information how the hash behaviors.

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