Skip to content

Commit 2d40631

Browse files
authored
recovers Merkle shreds using mutable references into shreds payloads (solana-labs#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.
1 parent e846335 commit 2d40631

File tree

2 files changed

+269
-270
lines changed

2 files changed

+269
-270
lines changed

ledger/src/shred/common.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ macro_rules! impl_shred_common {
4040
&self.payload
4141
}
4242

43+
#[inline]
4344
fn into_payload(self) -> Vec<u8> {
4445
self.payload
4546
}
4647

48+
#[inline]
4749
fn set_signature(&mut self, signature: Signature) {
48-
bincode::serialize_into(&mut self.payload[..], &signature).unwrap();
50+
self.payload[..SIZE_OF_SIGNATURE].copy_from_slice(signature.as_ref());
4951
self.common_header.signature = signature;
5052
}
5153

0 commit comments

Comments
 (0)