Skip to content

Commit

Permalink
LruCache faster snapshot (#5397)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scooletz committed Mar 8, 2023
1 parent e1bc1be commit a3d2c44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/Nethermind/Nethermind.Core/Caching/LruCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,17 @@ public bool Delete(TKey key)
public bool Contains(TKey key) => _cacheMap.ContainsKey(key);

[MethodImpl(MethodImplOptions.Synchronized)]
public IDictionary<TKey, TValue> Clone() => _cacheMap.ToDictionary(i => i.Key, i => i.Value.Value.Value);
public KeyValuePair<TKey, TValue>[] ToArray()
{
int i = 0;
KeyValuePair<TKey, TValue>[] array = new KeyValuePair<TKey, TValue>[_cacheMap.Count];
foreach (KeyValuePair<TKey, LinkedListNode<LruCacheItem>> kvp in _cacheMap)
{
array[i++] = new KeyValuePair<TKey, TValue>(kvp.Key, kvp.Value.Value.Value);
}

return array;
}

private void Replace(TKey key, TValue value)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Trie/CachingStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public byte[]? this[byte[] key]

public void PersistCache(IKeyValueStore pruningContext)
{
IDictionary<byte[], byte[]> clone = _cache.Clone();
KeyValuePair<byte[], byte[]>[] clone = _cache.ToArray();
Task.Run(() =>
{
foreach (KeyValuePair<byte[], byte[]> kvp in clone)
Expand Down

0 comments on commit a3d2c44

Please sign in to comment.