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

Remove from ConcurrentDict directly rather than building secondary list #5779

Merged
merged 1 commit into from
Jun 6, 2023
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
17 changes: 2 additions & 15 deletions src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,6 @@ private void PruneCache()
{
if (_logger.IsDebug) _logger.Debug($"Pruning nodes {MemoryUsedByDirtyCache / 1.MB()}MB , last persisted block: {LastPersistedBlockNumber} current: {LatestCommittedBlockNumber}.");
Stopwatch stopwatch = Stopwatch.StartNew();
List<TrieNode> toRemove = new(); // TODO: resettable

long newMemory = 0;
foreach ((ValueKeccak key, TrieNode node) in _dirtyNodes.AllNodes)
Expand All @@ -518,7 +517,7 @@ private void PruneCache()
throw new InvalidOperationException($"Persisted {node} {key} != {node.Keccak}");
}
}
toRemove.Add(node);
_dirtyNodes.Remove(node.Keccak);

Metrics.PrunedPersistedNodesCount++;
}
Expand All @@ -529,8 +528,7 @@ private void PruneCache()
{
throw new InvalidOperationException($"Removed {node}");
}

toRemove.Add(node);
_dirtyNodes.Remove(node.Keccak);

Metrics.PrunedTransientNodesCount++;
}
Expand All @@ -541,17 +539,6 @@ private void PruneCache()
}
}

for (int index = 0; index < toRemove.Count; index++)
{
TrieNode trieNode = toRemove[index];
if (trieNode.Keccak is null)
{
throw new InvalidOperationException($"{trieNode} has a null key");
}

_dirtyNodes.Remove(trieNode.Keccak);
}

MemoryUsedByDirtyCache = newMemory;
Metrics.CachedNodesCount = _dirtyNodes.Count;

Expand Down