Skip to content

Commit

Permalink
ed25519_verify_cpu: remove allocation in hot path (#3941)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alessandrod authored Dec 5, 2024
1 parent 6d0715a commit a53a876
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 @@ -515,18 +515,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 a53a876

Please sign in to comment.