-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
perf: minimize clones when saving blocks #12870
Conversation
very nice, appreciate this so much, ty |
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.
Are we sure that Arc::unwrap_or_clone
will unwrap in these cases? From what I can see, persistence codepath gets the block from the in-memory state, which in turn isn't pruned at the same time as the persistence is advanced, and is pruned later.
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.
That makes sense to me if Arc::unwrap_or_clone
actually unwraps, deferring to engine people here.
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.
smol nit, pending sanity review @klkvr
@@ -1,3 +1,5 @@ | |||
use std::sync::Arc; | |||
|
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.
please no more newline separations, this is driving me bananas 🙃
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.
Fixed 🥲.
@@ -155,15 +157,15 @@ where | |||
+ StaticFileProviderFactory, | |||
{ | |||
/// Writes executed blocks and receipts to storage. | |||
pub fn save_blocks(&self, blocks: &[ExecutedBlock]) -> ProviderResult<()> { | |||
pub fn save_blocks(&self, blocks: Vec<ExecutedBlock>) -> ProviderResult<()> { |
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.
imo this makes sense
// TODO: These writes should take ownership instead of cloning through | ||
// the reference just to (likely) drop the original afterwards. |
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.
unclear what this todo means, what is todo?
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.
I meant write_hashed_state
and write_trie_updates
should take the full data instead of a reference just to clone it within. That only makes sense if we want to persist the data afterwards, then we only need to clone the values instead of the whole structure. However, in this case, we don't need to persist the input data so passing the whole thing in would avoid any cloning. Should I elaborate or just remove the comment for now?
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.
Removed the comment. Will just do it in upcoming PRs that give better context anyway.
Yeah, that's why I chose "minimize" over "remove" like in previous PRs. I think the rule of thumb is to always use That said, looking at Edited: We don't need to re-insert as persistence failures are critical and shut down the node? |
7070e2e
to
a2e5f73
Compare
Read another page of
samply
while waiting for a meeting today 😅.There seem to be a lot of these (redundant allocations) in mempool, persistence, and root calculation hot paths. One PR at a time 🙏.