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

LruCache faster snapshot #5397

Merged
merged 1 commit into from
Mar 8, 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
LruCache faster snapshot
  • Loading branch information
Scooletz committed Mar 7, 2023
commit 36bb884eb7286e05fa566186c404084db7e151b9
12 changes: 11 additions & 1 deletion src/Nethermind/Nethermind.Core/Caching/LruCache.cs
Original file line number Diff line number Diff line change
@@ -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)
{
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Trie/CachingStore.cs
Original file line number Diff line number Diff line change
@@ -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)