Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

samlaf
Copy link

@samlaf samlaf commented Dec 20, 2024

from_bytes creates a copy of the passed slice. We can instead just use new directly which takes ownership of the blob, and prevents the copy, since we don't need it afterwards.

Copy link
Collaborator

@hashcashier hashcashier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the PR title should change because this doesn't actually remove the host-side memcpy it refers to, but uses the Copy trait instead.

Would be great if all host-side occurrences of from_bytes this could be replaced with this simpler variant though!

@@ -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();
Copy link
Collaborator

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.

@@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants