-
Notifications
You must be signed in to change notification settings - Fork 510
StorageValue #8482
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
Open
Scooletz
wants to merge
40
commits into
master
Choose a base branch
from
storage-value
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
StorageValue #8482
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A bit related to #8442 although working on a different level. |
LukaszRozmej
reviewed
Apr 9, 2025
Let's pause reviews for a while. Using more comparable machines showed different results from the ones presented before, showing that this branch is slower. |
asdacap
reviewed
Apr 11, 2025
b4d9ce1
to
e021927
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a notion of
StorageValue
that represents a non-trimmed 32-byte long value persisted contracts' storage. The main goal is to remove the clutter ofnew byte[]
that was used to keep the values and track the changes for the storage, and replace it with a simple struct. To make it work a storage is required to ammortize all data structures that previously hold a ref tobyte[]
and now need to keep theStorageValue
. The storage for it is calledStorageValueMap
and allows mapping an arbitrary value ofStorageValue
to a wrappedPtr
struct that is a size of a ref/ptr.The pointer is used in the storage cache, so that
ConcurrentDictionary
nodes should be smaller now (value is 8 bytes instead of 32) and should use less memory. They also directly return a platform size value so less copying will occur.The actual size of the amendment in
VirtualMachine
is small, as onlySLOAD
/SSTORE
TLOAD
/TSTORE
are affected. Additionally the tracing seam has been strongly amended.One more area that is touched is a different implementation of
.WithoutLeadingZeros()
that is ~ 1.5 times faster that theBytes.WithoutLeadingZeros()
. It uses the fact that we know the length and for 32 bytes it's easy to vectorize it.Additional cost of this approach is 36MB of memory that is never released, cleared or GCed.
Benchmarks
A set of benchmarks, using storage related methods: reset, reading with block cache warmed up and a cold cache. Additional set is added showing that the mapping penalty needs to be paid somewhere.
The benchmarks use
.IsZero
for making some operation on the retrieved value. The newIsZero
is quite fast as all it does isMicro-benchmarks
Before
After
CoarseGrained
Before
After
Running nodes
Comparison using GitHub action for RPC (comparable hardware)
Changes
Span<byte>
andbyte[]
based code for storageStorageValue
and its pointy counterpartPtr
VirtualMachine
in storage management opcodes, including gas calculationsTypes of changes
What types of changes does your code introduce?
Testing
Requires testing
If yes, did you write tests?
Notes on testing
Compare on various sizes of VMs
Documentation
Requires documentation update
Requires explanation in Release Notes