quic: use smallvec to aggregate chunks, save 1 alloc per packet (#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.
This commit is contained in:
Alessandro Decina 2024-04-11 12:25:35 +10:00 committed by GitHub
parent 85c6e412e0
commit 55ab7fadbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 8 deletions

5
Cargo.lock generated
View File

@ -5257,9 +5257,9 @@ checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5"
[[package]]
name = "smallvec"
version = "1.13.1"
version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]]
name = "smpl_jwt"
@ -7288,6 +7288,7 @@ dependencies = [
"quinn-proto",
"rand 0.8.5",
"rustls",
"smallvec",
"solana-logger",
"solana-measure",
"solana-metrics",

View File

@ -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"

View File

@ -4548,9 +4548,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]]
name = "smallvec"
version = "1.13.1"
version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]]
name = "smpl_jwt"
@ -6331,6 +6331,7 @@ dependencies = [
"quinn-proto",
"rand 0.8.5",
"rustls",
"smallvec",
"solana-measure",
"solana-metrics",
"solana-perf",

View File

@ -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 }

View File

@ -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::{
@ -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,
}
@ -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(),
});
}
@ -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,