Skip to content

Commit

Permalink
quic: use smallvec to aggregate chunks, save 1 alloc per packet (#735)
Browse files Browse the repository at this point in the history
quic: use smallvec, save one allocation per packet

Use smallvec to hold chunks. Streams are packet-sized so we don't expect
them to have many chunks. This saves us an allocation for each packet.
  • Loading branch information
alessandrod committed Apr 11, 2024
1 parent 85c6e41 commit 55ab7fa
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ sha2 = "0.10.8"
sha3 = "0.10.8"
signal-hook = "0.3.17"
siphasher = "0.3.11"
smallvec = "1.13.1"
smallvec = "1.13.2"
smpl_jwt = "0.7.1"
socket2 = "0.5.6"
soketto = "0.7"
Expand Down
5 changes: 3 additions & 2 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions streamer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ quinn = { workspace = true }
quinn-proto = { workspace = true }
rand = { workspace = true }
rustls = { workspace = true, features = ["dangerous_configuration"] }
smallvec = { workspace = true }
solana-measure = { workspace = true }
solana-metrics = { workspace = true }
solana-perf = { workspace = true }
Expand Down
7 changes: 4 additions & 3 deletions streamer/src/nonblocking/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use {
quinn::{Connecting, Connection, Endpoint, EndpointConfig, TokioRuntime, VarInt},
quinn_proto::VarIntBoundsExceeded,
rand::{thread_rng, Rng},
smallvec::SmallVec,
solana_measure::measure::Measure,
solana_perf::packet::{PacketBatch, PACKETS_PER_BATCH},
solana_sdk::{
Expand Down Expand Up @@ -96,7 +97,7 @@ struct PacketChunk {
// the Packet and then when copying the Packet into a PacketBatch)
struct PacketAccumulator {
pub meta: Meta,
pub chunks: Vec<PacketChunk>,
pub chunks: SmallVec<[PacketChunk; 2]>,
pub start_time: Instant,
}

Expand Down Expand Up @@ -934,7 +935,7 @@ async fn handle_chunk(
meta.set_from_staked_node(matches!(peer_type, ConnectionPeerType::Staked(_)));
*packet_accum = Some(PacketAccumulator {
meta,
chunks: Vec::new(),
chunks: SmallVec::new(),
start_time: Instant::now(),
});
}
Expand Down Expand Up @@ -1543,7 +1544,7 @@ pub mod test {
meta.size = size;
let packet_accum = PacketAccumulator {
meta,
chunks: vec![PacketChunk {
chunks: smallvec::smallvec![PacketChunk {
bytes,
offset,
end_of_chunk: size,
Expand Down

0 comments on commit 55ab7fa

Please sign in to comment.