Skip to content

Commit

Permalink
v2.1: ed25519_verify_cpu: remove allocation in hot path (backport of …
Browse files Browse the repository at this point in the history
…#3941) (#3945)

ed25519_verify_cpu: remove allocation in hot path (#3941)

The old code was a remnant from a time when we tried to "balance" the
amount of work across threads by re-batching and therefore allocating.

This is a hot path. Allocations are bad. Let work stealing work its
magic.

(cherry picked from commit a53a876)

Co-authored-by: Alessandro Decina <[email protected]>
  • Loading branch information
mergify[bot] and alessandrod authored Jan 8, 2025
1 parent be346e7 commit bc18e44
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions perf/src/sigverify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,18 +517,11 @@ pub fn shrink_batches(batches: &mut Vec<PacketBatch>) {
pub fn ed25519_verify_cpu(batches: &mut [PacketBatch], reject_non_vote: bool, packet_count: usize) {
debug!("CPU ECDSA for {}", packet_count);
PAR_THREAD_POOL.install(|| {
batches
.par_iter_mut()
.flatten()
.collect::<Vec<&mut Packet>>()
.par_chunks_mut(VERIFY_PACKET_CHUNK_SIZE)
.for_each(|packets| {
for packet in packets.iter_mut() {
if !packet.meta().discard() && !verify_packet(packet, reject_non_vote) {
packet.meta_mut().set_discard(true);
}
}
});
batches.par_iter_mut().flatten().for_each(|packet| {
if !packet.meta().discard() && !verify_packet(packet, reject_non_vote) {
packet.meta_mut().set_discard(true);
}
});
});
}

Expand Down

0 comments on commit bc18e44

Please sign in to comment.