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

Recheck if empty under lock, early exit #7442

Merged
merged 8 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ public static void AddRange<T>(this ICollection<T> list, params T[] items)
public static bool NoResizeClear<TKey, TValue>(this ConcurrentDictionary<TKey, TValue>? dictionary)
where TKey : notnull
{
if (dictionary is null || dictionary.IsEmpty)
if (dictionary?.IsEmpty ?? true)
{
return false;
}

using var handle = dictionary.AcquireLock();

// Recheck under lock, so not to over clear which is expensive.
// May have cleared while waiting for lock.
if (dictionary.IsEmpty)
{
return false;
}

ClearCache<TKey, TValue>.Clear(dictionary);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ public void CommitTrees(long blockNumber)
_toUpdateRoots.Clear();
// only needed here as there is no control over cached storage size otherwise
_storages.Clear();
_preBlockCache?.NoResizeClear();
}

private StorageTree GetOrCreateStorage(Address address)
Expand Down
1 change: 0 additions & 1 deletion src/Nethermind/Nethermind.State/StateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,6 @@ public void CommitTree(long blockNumber)
}

_tree.Commit(blockNumber);
_preBlockCache?.NoResizeClear();
}

public static void CommitBranch()
Expand Down