Skip to content

Commit

Permalink
recovers Merkle shreds using mutable references into shreds payloads (#…
Browse files Browse the repository at this point in the history
…4356)

Erasure recovery for Merkle shreds copies the erasure shards out of the
shreds:
https://github.com/anza-xyz/agave/blob/df5c9ad28/ledger/src/shred/merkle.rs#L893
and then resizes and copies recovered shards after erasure recovery
which might cause another re-allocation:
https://github.com/anza-xyz/agave/blob/df5c9ad28/ledger/src/shred/merkle.rs#L157-L158
https://github.com/anza-xyz/agave/blob/df5c9ad28/ledger/src/shred/merkle.rs#L246-L247

In order to minimize allocations and memory copies, this commit instead
uses mutable references into the shred payload, passing them directly as
shards to the Reed-Solomon implementation.
  • Loading branch information
behzadnouri authored Jan 10, 2025
1 parent e846335 commit 2d40631
Show file tree
Hide file tree
Showing 2 changed files with 269 additions and 270 deletions.
4 changes: 3 additions & 1 deletion ledger/src/shred/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ macro_rules! impl_shred_common {
&self.payload
}

#[inline]
fn into_payload(self) -> Vec<u8> {
self.payload
}

#[inline]
fn set_signature(&mut self, signature: Signature) {
bincode::serialize_into(&mut self.payload[..], &signature).unwrap();
self.payload[..SIZE_OF_SIGNATURE].copy_from_slice(signature.as_ref());
self.common_header.signature = signature;
}

Expand Down
Loading

0 comments on commit 2d40631

Please sign in to comment.