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
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 committed Jan 9, 2025
1 parent 2a4a1ac commit 444d71f
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 444d71f

Please sign in to comment.