Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the empty account cache as cache #6452

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/Nethermind/Nethermind.State/StateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal class StateProvider
private const int StartCapacity = Resettable.StartCapacity;
private readonly ResettableDictionary<Address, Stack<int>> _intraBlockCache = new();
private readonly ResettableHashSet<Address> _committedThisRound = new();
private readonly HashSet<Address> _nullAccountReads = new();
// Only guarding against hot duplicates so filter doesn't need to be too big
// Note:
// False negatives are fine as they will just result in a overwrite set
Expand Down Expand Up @@ -508,7 +509,7 @@ public void Commit(IReleaseSpec releaseSpec, IWorldStateTracer stateTracer, bool
// because it was not committed yet it means that the just cache is the only state (so it was read only)
if (isTracing && change.ChangeType == ChangeType.JustCache)
{
_readsForTracing.Add(change.Address);
_nullAccountReads.Add(change.Address);
continue;
}

Expand Down Expand Up @@ -597,7 +598,7 @@ public void Commit(IReleaseSpec releaseSpec, IWorldStateTracer stateTracer, bool

if (isTracing)
{
foreach (Address nullRead in _readsForTracing)
foreach (Address nullRead in _nullAccountReads)
{
// // this may be enough, let us write tests
stateTracer.ReportAccountRead(nullRead);
Expand All @@ -606,7 +607,7 @@ public void Commit(IReleaseSpec releaseSpec, IWorldStateTracer stateTracer, bool

Resettable<Change>.Reset(ref _changes, ref _capacity, ref _currentPosition, StartCapacity);
_committedThisRound.Reset();
_readsForTracing.Clear();
_nullAccountReads.Clear();
_intraBlockCache.Reset();

if (isTracing)
Expand Down Expand Up @@ -687,10 +688,10 @@ private void SetState(Address address, Account? account)
_tree.Set(address, account);
}

private readonly HashSet<Address> _readsForTracing = new();

private Account? GetAndAddToCache(Address address)
{
if (_nullAccountReads.Contains(address)) return null;

Account? account = GetState(address);
if (account is not null)
{
Expand All @@ -699,7 +700,7 @@ private void SetState(Address address, Account? account)
else
{
// just for tracing - potential perf hit, maybe a better solution?
_readsForTracing.Add(address);
_nullAccountReads.Add(address);
}

return account;
Expand Down Expand Up @@ -803,7 +804,7 @@ public void Reset()
if (_logger.IsTrace) _logger.Trace("Clearing state provider caches");
_intraBlockCache.Reset();
_committedThisRound.Reset();
_readsForTracing.Clear();
_nullAccountReads.Clear();
_currentPosition = Resettable.EmptyPosition;
Array.Clear(_changes, 0, _changes.Length);
_needsStateRootUpdate = false;
Expand Down
Loading