Skip to content

Commit

Permalink
Remove from ConcurrentDict directly rather than building secondary li…
Browse files Browse the repository at this point in the history
…st (#5779)
  • Loading branch information
benaadams authored Jun 6, 2023
1 parent 3a96f5e commit 39f2da1
Showing 1 changed file with 2 additions and 15 deletions.
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

0 comments on commit 39f2da1

Please sign in to comment.