-
Couldn't load subscription status.
- Fork 1k
Serialized storage cache #3669
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
base: master
Are you sure you want to change the base?
Serialized storage cache #3669
Changes from 45 commits
37217b6
f0bfc3b
038a7c4
ccce7a4
4943659
cca66ba
54901ed
75f5a06
ecdfe09
83d13cc
5230d9c
df7ad8e
be5db33
c12767a
601c366
6bdcc21
9c45d94
5fb4b62
3d25c9f
413d605
2dd2301
336cbac
9decaf0
bb6ca9c
a84c163
3c6d292
bf97fab
62ae410
ac22a4d
a21526f
f0a9add
a917235
f4b5bcd
6d1d8a0
6bd4f42
aa3b705
e4e8130
b5f03e2
d31d182
c6a7c00
e503094
13b3e50
a96bdbc
3bf2240
53215b7
64b2796
898d3e6
1d971bf
894f979
3a7bf7a
1f5af5c
5f80417
fa7ec14
ce5ec54
f7ae9de
6f30414
c277a80
6af2e0c
3bc447a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Copyright (C) 2015-2025 The Neo Project. | ||
| // | ||
| // Benchmarks.Cache.cs file belongs to the neo project and is free | ||
| // software distributed under the MIT software license, see the | ||
| // accompanying file LICENSE in the main directory of the | ||
| // repository or http://www.opensource.org/licenses/mit-license.php | ||
| // for more details. | ||
| // | ||
| // Redistribution and use in source and binary forms with or without | ||
| // modifications are permitted. | ||
|
|
||
| using BenchmarkDotNet.Attributes; | ||
| using Neo.Persistence; | ||
| using Neo.SmartContract; | ||
| using Neo.SmartContract.Native; | ||
| using System.Numerics; | ||
|
|
||
| namespace Neo.Benchmark | ||
| { | ||
| public class Benchmarks_Cache | ||
| { | ||
| // 256 KiB | ||
| readonly MemoryStore _store; | ||
| readonly StoreCache _snapshot; | ||
|
|
||
| public Benchmarks_Cache() | ||
| { | ||
| _store = new MemoryStore(); | ||
| _snapshot = new(_store.GetSnapshot()); | ||
|
|
||
| // Ledger.CurrentIndex | ||
|
|
||
| _snapshot.GetAndChange(new KeyBuilder(NativeContract.Ledger.Id, 12), () => new StorageItem(new HashIndexState() { Hash = UInt256.Zero, Index = 2 })); | ||
|
|
||
| // Gas Per block | ||
|
|
||
| _snapshot.GetAndChange(new KeyBuilder(NativeContract.NEO.Id, 29).AddBigEndian(0), () => new StorageItem(0)); | ||
| _snapshot.GetAndChange(new KeyBuilder(NativeContract.NEO.Id, 29).AddBigEndian(1), () => new StorageItem(1)); | ||
| _snapshot.GetAndChange(new KeyBuilder(NativeContract.NEO.Id, 29).AddBigEndian(2), () => new StorageItem(2)); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void WithCache() | ||
| { | ||
| for (var x = 0; x < 1_000; x++) | ||
| { | ||
| var ret = NativeContract.NEO.GetGasPerBlock(_snapshot); | ||
| if (ret != 2) throw new Exception("Test error"); | ||
| } | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void WithoutCache() | ||
| { | ||
| for (var x = 0; x < 1_000; x++) | ||
| { | ||
| var ret = OldCode(); | ||
| if (ret != 2) throw new Exception("Test error"); | ||
| } | ||
| } | ||
|
|
||
| private BigInteger OldCode() | ||
| { | ||
| var end = NativeContract.Ledger.CurrentIndex(_snapshot) + 1; | ||
| var last = NativeContract.NEO.GetSortedGasRecords(_snapshot, end).First(); | ||
| return last.GasPerBlock; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,12 +11,10 @@ | |
|
|
||
| using BenchmarkDotNet.Running; | ||
| using Neo.Benchmark; | ||
| using Neo.Benchmarks.Persistence.Benchmarks; | ||
| using Neo.SmartContract.Benchmark; | ||
|
|
||
| // BenchmarkRunner.Run<Benchmarks_PoCs>(); | ||
| BenchmarkRunner.Run<Benchmarks_UInt160>(); | ||
| BenchmarkRunner.Run<Benchmarks_Hash>(); | ||
| BenchmarkRunner.Run<Benchmarks_StorageKey>(); | ||
| BenchmarkRunner.Run<Bechmarks_ReadOnlyStoreView>(); | ||
| BenchmarkRunner.Run<Bechmarks_LevelDB>(); | ||
| BenchmarkRunner.Run<Benchmarks_Cache>(); | ||
| //BenchmarkRunner.Run<Benchmarks_UInt160>(); | ||
|
||
| //BenchmarkRunner.Run<Benchmarks_Hash>(); | ||
| //BenchmarkRunner.Run<Benchmarks_StorageKey>(); | ||
| //BenchmarkRunner.Run<Bechmarks_ReadOnlyStoreView>(); | ||
| //BenchmarkRunner.Run<Bechmarks_LevelDB>(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright (C) 2015-2025 The Neo Project. | ||
| // | ||
| // ICacheableReadOnlyStore.cs file belongs to the neo project and is free | ||
| // software distributed under the MIT software license, see the | ||
| // accompanying file LICENSE in the main directory of the | ||
| // repository or http://www.opensource.org/licenses/mit-license.php | ||
| // for more details. | ||
| // | ||
| // Redistribution and use in source and binary forms with or without | ||
| // modifications are permitted. | ||
|
|
||
| #nullable enable | ||
|
|
||
| using Neo.SmartContract; | ||
| using System; | ||
|
|
||
| namespace Neo.Persistence | ||
| { | ||
| /// <summary> | ||
| /// This interface provides methods to read from the database. | ||
| /// </summary> | ||
| public interface ICacheableReadOnlyStore : ICacheableReadOnlyStore<StorageKey, StorageItem>, IReadOnlyStore { } | ||
|
|
||
| /// <summary> | ||
| /// This interface provides methods to read from the database. | ||
| /// </summary> | ||
| public interface ICacheableReadOnlyStore<TKey, TValue> : IReadOnlyStore<TKey, TValue> | ||
| { | ||
| /// <summary> | ||
| /// Tries to get the entry from cache. | ||
| /// </summary> | ||
| /// <typeparam name="T">Cache type</typeparam> | ||
| /// <returns>The entry if found, null otherwise.</returns> | ||
| public T? GetFromCache<T>() where T : IStorageCacheEntry; | ||
|
|
||
| /// <summary> | ||
| /// Adds a new entry to the cache. | ||
| /// </summary> | ||
| /// <param name="value">The data of the entry.</param> | ||
| /// <exception cref="ArgumentException">The entry has already been cached.</exception> | ||
| /// <remarks>Note: This method does not read the internal storage to check whether the record already exists.</remarks> | ||
| public void AddToCache<T>(T? value = default) where T : IStorageCacheEntry; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Copyright (C) 2015-2025 The Neo Project. | ||
| // | ||
| // IStorageCacheEntry.cs file belongs to the neo project and is free | ||
| // software distributed under the MIT software license, see the | ||
| // accompanying file LICENSE in the main directory of the | ||
| // repository or http://www.opensource.org/licenses/mit-license.php | ||
| // for more details. | ||
| // | ||
| // Redistribution and use in source and binary forms with or without | ||
| // modifications are permitted. | ||
|
|
||
| using Neo.SmartContract; | ||
|
|
||
| namespace Neo.Persistence | ||
| { | ||
| public interface IStorageCacheEntry | ||
| { | ||
| public StorageItem GetStorageItem(); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.