trie: don't copy when we are the exclusive owner of the trie
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.
core/state/trie_prefetcher: mark the returned trie as unshared when possible
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.
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.