trie, trie_prefetcher: don't copy when we are the exclusive owner of the trie #592
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, to make the trie copy perform well, we only copy the trie's node on
write. However, there is no tracking on whether the trie is copied or not, so we
always perform copy-on-write even though we are the only owner of the trie. This
commit adds a shared bool to trie, this is set when trie copy is performed. When
the trie is not shared, it is safe to do all the modification in-place without
the need of creating a new copy.
Trie's modification is more optimized when it's marked as unshared. When the
prefetched trie is requested, the prefetcher is stopped and the caller can
become the exclusive owner of the trie in most case. When the prefetcher is not
copied (active prefetcher), when possible, the returned trie is marked as
unshared. However, we need to be careful as there might be the case that 2 same
storage trie are prefetched. In that case, don't mark the trie as unshared when
returning to caller.