refactor state diffs not to require two states in memory #4986
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.
It wasn't feasible to integrate before into the rest of Nimbus without substantially increasing memory consumption due to holding a previous state in memory. However, the diff didn't use the vast majority of the previous state, so this uses a small, intermediate object which can be safely buffered.
With 600k validators, this object is still not tiny, but it's not part of the serialized compatibility surface, so can be optimized as warranted by either using a bitmap (8x less memory, less than 100KiB, constant regardless of what kind of validators exist) or optimizing by omitting certain kinds of withdrawal credentials (needs more than 1 bit of memory, because then some sort of either sparse or offset representation has to be used; a
PackedSet
would be reasonable).Either way, this is simple, reasonably efficient in both time and space, and uses only built-in data structures.