-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
removes redundant vector allocations before calling sendmmsg::batch_send #4129
removes redundant vector allocations before calling sendmmsg::batch_send #4129
Conversation
365214b
to
43d93a0
Compare
19acb5b
to
bbb62dc
Compare
d73c5db
to
0142799
Compare
0142799
to
8ed7047
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
6cedd30
to
1e221d9
Compare
@@ -1249,14 +1249,13 @@ impl ServeRepair { | |||
} | |||
} | |||
if !pending_pongs.is_empty() { | |||
match batch_send(repair_socket, &pending_pongs) { | |||
let num_pkts = pending_pongs.len(); | |||
let pending_pongs = pending_pongs.iter().map(|(bytes, addr)| (bytes, addr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks redundant... why map without any actual transform?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The closure is converting &(S, T)
to (&S, &T)
.
The code will not build without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see. rust sometimes works in mysterious ways!
@@ -362,7 +362,7 @@ fn recv_send( | |||
let data = pkt.data(..)?; | |||
socket_addr_space.check(&addr).then_some((data, addr)) | |||
}); | |||
batch_send(sock, &packets.collect::<Vec<_>>())?; | |||
batch_send(sock, packets.collect::<Vec<_>>())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we still doing collect here if we can pass iterators now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need an ExactSizeIterator
. A filter_map
is not an ExactSizeIterator
because the number of items filtered out are not known.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this is probably a good direction given how many packets we send. Left a few small questions in the code.
streamer::sendmmsg::batch_send only requires an ExactSizeIterator: https://github.com/anza-xyz/agave/blob/566bb9565/streamer/src/sendmmsg.rs#L203-L204 https://github.com/anza-xyz/agave/blob/566bb9565/streamer/src/sendmmsg.rs#L166-L175 Collecting an iterator into a vector before calling batch_send is unnecessary and only adds overhead. In particular multi_target_send used in retransmitting shreds can be use without doing an additional vector allocation: https://github.com/anza-xyz/agave/blob/566bb9565/streamer/src/sendmmsg.rs#L219
1e221d9
to
774f0d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to go
Problem
streamer::sendmmsg::batch_send
only requires anExactSizeIterator
:https://github.com/anza-xyz/agave/blob/82347779f/streamer/src/sendmmsg.rs#L169-L175
Collecting an iterator into a vector before calling
batch_send
is unnecessary and only adds overhead.In particular
multi_target_send
used in retransmitting shreds can be use without doing an additional vector allocation:https://github.com/anza-xyz/agave/blob/82347779f/streamer/src/sendmmsg.rs#L197
Summary of Changes
Removed redundant vector allocations before calling
streamer::sendmmsg::batch_send
.