-
Notifications
You must be signed in to change notification settings - Fork 7
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(client): prevent unneeded memory copy in BlobWitnessProvider #5
Changes from all commits
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 |
---|---|---|
|
@@ -44,7 +44,7 @@ impl<T: BlobProvider + Send> BlobProvider for BlobWitnessProvider<T> { | |
) -> Result<Vec<Box<Blob>>, Self::Error> { | ||
let blobs = self.provider.get_blobs(block_ref, blob_hashes).await?; | ||
for blob in &blobs { | ||
let c_kzg_blob = c_kzg::Blob::from_bytes(blob.as_slice()).unwrap(); | ||
let c_kzg_blob = c_kzg::Blob::new(***blob); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this change makes the copy implicit (via Copy trait) racer than explicit via from slice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah you might be right!
Could the fact that its C representation mean its actually moved and not copied? If not, then you're right and I will just close this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel like c-kzg should have a move constructor though...! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The memory representation doesn't affect the borrow checker afaik There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After reading a bit more, pretty convinced also this is true. But also don't think the borrow checker and the fact that a struct implements the Copy trait actually means it will be copied when passed into a function that doesn't modify it, because those are lower level concerns. Rust passes arguments by value, but I think it is also able to perform https://en.wikipedia.org/wiki/Copy_elision like C++. Hence I do think the change in this PR could help (probably only when building with --release to have compiler optimizations). Nonetheless, this change would make a lot more sense if I implemented it uniformly across the codebase, and wrote some benchmark to actually show that it helps. So I'll close for now. Enjoy your holiday break! :) |
||
let settings = alloy::consensus::EnvKzgSettings::default(); | ||
let commitment = | ||
c_kzg::KzgCommitment::blob_to_kzg_commitment(&c_kzg_blob, settings.get()) | ||
|
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.
This isn't the only host-side occurrence of using
from_bytes
.