-
Notifications
You must be signed in to change notification settings - Fork 2k
perf(storage): optimize wiped storage entry collection to avoid Vec allocation #19127
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: main
Are you sure you want to change the base?
Conversation
|
Please review @yongkangc @mattsse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we could simplify this without the abstraction
ref:
| fn write_storage_trie_changesets<'a>( |
| pub struct WipedStorageIter<'a, C> { | ||
| cursor: &'a mut C, | ||
| address: alloy_primitives::Address, | ||
| is_first: bool, | ||
| has_more: bool, | ||
| } | ||
|
|
||
| impl<'a, C> WipedStorageIter<'a, C> | ||
| where | ||
| C: DbCursorRO<PlainStorageState> + DbDupCursorRO<PlainStorageState>, | ||
| { | ||
| /// Create a new iterator for wiped storage entries at the given address. | ||
| pub fn new( | ||
| cursor: &'a mut C, | ||
| address: alloy_primitives::Address, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we do it in a simpler way where we don't need this abstraction?
this abstraction seems to make it more complicated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified and reverted!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes the collection of wiped storage entries by replacing an intermediate Vec allocation with a streaming iterator that processes entries directly from the database cursor.
Key Changes:
- Introduces
WipedStorageIterfor lazy iteration over wiped storage entries - Refactors storage revert writing to use the new iterator instead of collecting into a Vec
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/storage/provider/src/changesets_utils/wiped_storage.rs | New file implementing WipedStorageIter for streaming wiped storage entries |
| crates/storage/provider/src/changesets_utils/mod.rs | Exports the new WipedStorageIter type |
| crates/storage/provider/src/providers/database/provider.rs | Replaces Vec collection with WipedStorageIter in storage revert writing |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Resolves #19077
Replaced the intermediate collection with a streaming iterator (
WipedStorageIter) that processes wiped entries directly from the database cursor.