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.

(cherry picked from commit 55ab7fa)

# Conflicts:
#	programs/sbf/Cargo.lock
#	streamer/Cargo.toml
#	streamer/src/nonblocking/quic.rs
  • Loading branch information
alessandrod authored and mergify[bot] committed Apr 11, 2024
1 parent cf5e8d3 commit 634d4b6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 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
9 changes: 7 additions & 2 deletions programs/sbf/Cargo.lock

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

5 changes: 5 additions & 0 deletions streamer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ quinn-proto = { workspace = true }
rand = { workspace = true }
rcgen = { workspace = true }
rustls = { workspace = true, features = ["dangerous_configuration"] }
<<<<<<< HEAD
=======
smallvec = { workspace = true }
solana-measure = { workspace = true }
>>>>>>> 55ab7fadbc (quic: use smallvec to aggregate chunks, save 1 alloc per packet (#735))
solana-metrics = { workspace = true }
solana-perf = { workspace = true }
solana-sdk = { workspace = true }
Expand Down
17 changes: 16 additions & 1 deletion streamer/src/nonblocking/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ use {
quinn::{Connecting, Connection, Endpoint, EndpointConfig, TokioRuntime, VarInt},
quinn_proto::VarIntBoundsExceeded,
rand::{thread_rng, Rng},
<<<<<<< HEAD
=======
smallvec::SmallVec,
solana_measure::measure::Measure,
>>>>>>> 55ab7fadbc (quic: use smallvec to aggregate chunks, save 1 alloc per packet (#735))
solana_perf::packet::{PacketBatch, PACKETS_PER_BATCH},
solana_sdk::{
packet::{Meta, PACKET_DATA_SIZE},
Expand Down Expand Up @@ -93,7 +98,12 @@ struct PacketChunk {
// the Packet and then when copying the Packet into a PacketBatch)
struct PacketAccumulator {
pub meta: Meta,
<<<<<<< HEAD
pub chunks: Vec<PacketChunk>,
=======
pub chunks: SmallVec<[PacketChunk; 2]>,
pub start_time: Instant,
>>>>>>> 55ab7fadbc (quic: use smallvec to aggregate chunks, save 1 alloc per packet (#735))
}

#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -872,7 +882,12 @@ async fn handle_chunk(
meta.set_socket_addr(remote_addr);
*packet_accum = Some(PacketAccumulator {
meta,
<<<<<<< HEAD
chunks: Vec::new(),
=======
chunks: SmallVec::new(),
start_time: Instant::now(),
>>>>>>> 55ab7fadbc (quic: use smallvec to aggregate chunks, save 1 alloc per packet (#735))
});
}

Expand Down Expand Up @@ -1471,7 +1486,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 634d4b6

Please sign in to comment.