Skip to content

Commit

Permalink
v1.18: quic: use smallvec to aggregate chunks, save 1 alloc per packe…
Browse files Browse the repository at this point in the history
…t (backport of anza-xyz#735) (anza-xyz#742)

quic: use smallvec to aggregate chunks, save 1 alloc per packet (anza-xyz#735)

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.

(cherry picked from commit 55ab7fa)

# Conflicts:
#	programs/sbf/Cargo.lock
#	streamer/Cargo.toml
#	streamer/src/nonblocking/quic.rs

Co-authored-by: Alessandro Decina <alessandro.d@gmail.com>
  • Loading branch information
2 people authored and yihau committed Apr 11, 2024
1 parent f2ea237 commit 2ed208c
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 @@ -303,7 +303,7 @@ sha2 = "0.10.8"
sha3 = "0.10.4"
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.5"
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 @@ -28,6 +28,7 @@ quinn-proto = { workspace = true }
rand = { workspace = true }
rcgen = { workspace = true }
rustls = { workspace = true, features = ["dangerous_configuration"] }
smallvec = { workspace = true }
solana-metrics = { workspace = true }
solana-perf = { workspace = true }
solana-sdk = { 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 @@ -17,6 +17,7 @@ use {
quinn::{Connecting, Connection, Endpoint, EndpointConfig, TokioRuntime, VarInt},
quinn_proto::VarIntBoundsExceeded,
rand::{thread_rng, Rng},
smallvec::SmallVec,
solana_perf::packet::{PacketBatch, PACKETS_PER_BATCH},
solana_sdk::{
packet::{Meta, PACKET_DATA_SIZE},
Expand Down Expand Up @@ -93,7 +94,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]>,
}

#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -872,7 +873,7 @@ async fn handle_chunk(
meta.set_socket_addr(remote_addr);
*packet_accum = Some(PacketAccumulator {
meta,
chunks: Vec::new(),
chunks: SmallVec::new(),
});
}

Expand Down Expand Up @@ -1471,7 +1472,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 2ed208c

Please sign in to comment.