Skip to content

ci: Try and avoid large pass-by-value instances #2623

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ disallowed-macros = [
allow-mixed-uninlined-format-args = false
allow-unwrap-in-tests = true
allow-dbg-in-tests = true
pass-by-value-size-limit = 16
# avoid-breaking-exported-api = false # TODO: Enable this in a follow-on PR.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 change: 1 addition & 0 deletions neqo-bin/src/client/http09.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl super::Handler for Handler<'_> {
}
}

#[expect(clippy::large_types_passed_by_value, reason = "This wants values.")]
pub fn create_client(
args: &Args,
local_addr: SocketAddr,
Expand Down
1 change: 1 addition & 0 deletions neqo-bin/src/client/http3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl<'a> Handler<'a> {
}
}

#[expect(clippy::large_types_passed_by_value, reason = "This wants values.")]
pub fn create_client(
args: &Args,
local_addr: SocketAddr,
Expand Down
8 changes: 4 additions & 4 deletions neqo-bin/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ trait Client {
}

struct Runner<'a, H: Handler> {
local_addr: SocketAddr,
local_addr: &'a SocketAddr,
socket: &'a mut crate::udp::Socket,
client: H::Client,
handler: H,
Expand All @@ -409,7 +409,7 @@ struct Runner<'a, H: Handler> {

impl<'a, H: Handler> Runner<'a, H> {
fn new(
local_addr: SocketAddr,
local_addr: &'a SocketAddr,
socket: &'a mut crate::udp::Socket,
client: H::Client,
handler: H,
Expand Down Expand Up @@ -611,7 +611,7 @@ pub async fn client(mut args: Args) -> Res<()> {

let handler = http3::Handler::new(to_request, &args);

Runner::new(real_local, &mut socket, client, handler, &args)
Runner::new(&real_local, &mut socket, client, handler, &args)
.run()
.await?
} else {
Expand All @@ -621,7 +621,7 @@ pub async fn client(mut args: Args) -> Res<()> {

let handler = http09::Handler::new(to_request, &args);

Runner::new(real_local, &mut socket, client, handler, &args)
Runner::new(&real_local, &mut socket, client, handler, &args)
.run()
.await?
};
Expand Down
15 changes: 8 additions & 7 deletions neqo-bin/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@ impl ServerRunner {
}

/// Tries to find a socket, but then just falls back to sending from the first.
fn find_socket(
sockets: &mut [(SocketAddr, crate::udp::Socket)],
addr: SocketAddr,
) -> &mut crate::udp::Socket {
fn find_socket<'a>(
sockets: &'a mut [(SocketAddr, crate::udp::Socket)],
addr: &SocketAddr,
) -> &'a mut crate::udp::Socket {
let ((_host, first_socket), rest) = sockets.split_first_mut().unwrap();
rest.iter_mut()
.map(|(_host, socket)| socket)
.find(|socket| socket.local_addr().is_ok_and(|a| a == addr))
.find(|socket| socket.local_addr().is_ok_and(|a| a == *addr))
.unwrap_or(first_socket)
}

Expand All @@ -255,7 +255,7 @@ impl ServerRunner {
loop {
match server.process(input_dgram.take(), now()) {
Output::Datagram(dgram) => {
let socket = Self::find_socket(sockets, dgram.source());
let socket = Self::find_socket(sockets, &dgram.source());
loop {
// Optimistically attempt sending datagram. In case the
// OS buffer is full, wait till socket is writable then
Expand Down Expand Up @@ -284,7 +284,8 @@ impl ServerRunner {
async fn read_and_process(&mut self, sockets_index: usize) -> Result<(), io::Error> {
loop {
let (host, socket) = &mut self.sockets[sockets_index];
let Some(input_dgrams) = socket.recv(*host, &mut self.recv_buf)? else {
let host = *host;
let Some(input_dgrams) = socket.recv(&host, &mut self.recv_buf)? else {
break;
};

Expand Down
2 changes: 1 addition & 1 deletion neqo-bin/src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Socket {
/// the provided local address.
pub fn recv<'a>(
&self,
local_address: SocketAddr,
local_address: &'a SocketAddr,
recv_buf: &'a mut RecvBuf,
) -> Result<Option<DatagramIter<'a>>, io::Error> {
self.inner
Expand Down
12 changes: 6 additions & 6 deletions neqo-http3/src/client_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ pub struct Http3ClientEvents {

impl RecvStreamEvents for Http3ClientEvents {
/// Add a new `DataReadable` event
fn data_readable(&self, stream_info: Http3StreamInfo) {
fn data_readable(&self, stream_info: &Http3StreamInfo) {
self.insert(Http3ClientEvent::DataReadable {
stream_id: stream_info.stream_id(),
});
}

/// Add a new `Reset` event.
fn recv_closed(&self, stream_info: Http3StreamInfo, close_type: CloseType) {
fn recv_closed(&self, stream_info: &Http3StreamInfo, close_type: CloseType) {
let stream_id = stream_info.stream_id();
let (local, error) = match close_type {
CloseType::ResetApp(_) => {
Expand Down Expand Up @@ -149,7 +149,7 @@ impl HttpRecvStreamEvents for Http3ClientEvents {
/// Add a new `HeaderReady` event.
fn header_ready(
&self,
stream_info: Http3StreamInfo,
stream_info: &Http3StreamInfo,
headers: Vec<Header>,
interim: bool,
fin: bool,
Expand All @@ -165,13 +165,13 @@ impl HttpRecvStreamEvents for Http3ClientEvents {

impl SendStreamEvents for Http3ClientEvents {
/// Add a new `DataWritable` event.
fn data_writable(&self, stream_info: Http3StreamInfo) {
fn data_writable(&self, stream_info: &Http3StreamInfo) {
self.insert(Http3ClientEvent::DataWritable {
stream_id: stream_info.stream_id(),
});
}

fn send_closed(&self, stream_info: Http3StreamInfo, close_type: CloseType) {
fn send_closed(&self, stream_info: &Http3StreamInfo, close_type: CloseType) {
let stream_id = stream_info.stream_id();
self.remove_send_stream_events(stream_id);
if let CloseType::ResetRemote(error) = close_type {
Expand Down Expand Up @@ -219,7 +219,7 @@ impl ExtendedConnectEvents for Http3ClientEvents {
}
}

fn extended_connect_new_stream(&self, stream_info: Http3StreamInfo) -> Res<()> {
fn extended_connect_new_stream(&self, stream_info: &Http3StreamInfo) -> Res<()> {
self.insert(Http3ClientEvent::WebTransport(
WebTransportEvent::NewStream {
stream_id: stream_info.stream_id(),
Expand Down
2 changes: 1 addition & 1 deletion neqo-http3/src/features/extended_connect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub(crate) trait ExtendedConnectEvents: Debug {
reason: SessionCloseReason,
headers: Option<Vec<Header>>,
);
fn extended_connect_new_stream(&self, stream_info: Http3StreamInfo) -> Res<()>;
fn extended_connect_new_stream(&self, stream_info: &Http3StreamInfo) -> Res<()>;
fn new_datagram(&self, session_id: StreamId, datagram: Vec<u8>);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl WebTransportSession {

if !stream_id.is_self_initiated(self.role) {
self.events
.extended_connect_new_stream(Http3StreamInfo::new(
.extended_connect_new_stream(&Http3StreamInfo::new(
stream_id,
ExtendedConnectType::WebTransport.get_stream_type(self.session_id),
))?;
Expand Down Expand Up @@ -527,7 +527,7 @@ impl RecvStreamEvents for Rc<RefCell<WebTransportSessionListener>> {}
impl HttpRecvStreamEvents for Rc<RefCell<WebTransportSessionListener>> {
fn header_ready(
&self,
_stream_info: Http3StreamInfo,
_stream_info: &Http3StreamInfo,
headers: Vec<Header>,
interim: bool,
fin: bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct WebTransportRecvStream {
session: Rc<RefCell<WebTransportSession>>,
session_id: StreamId,
fin: bool,
stream_info: Http3StreamInfo,
}

impl WebTransportRecvStream {
Expand All @@ -40,11 +41,12 @@ impl WebTransportRecvStream {
session_id,
session,
fin: false,
stream_info: Http3StreamInfo::new(stream_id, Http3StreamType::WebTransport(session_id)),
}
}

fn get_info(&self) -> Http3StreamInfo {
Http3StreamInfo::new(self.stream_id, self.stream_type())
const fn get_info(&self) -> &Http3StreamInfo {
&self.stream_info
}
}

Expand Down Expand Up @@ -121,6 +123,7 @@ pub struct WebTransportSendStream {
events: Box<dyn SendStreamEvents>,
session: Rc<RefCell<WebTransportSession>>,
session_id: StreamId,
stream_info: Http3StreamInfo,
}

impl WebTransportSendStream {
Expand Down Expand Up @@ -151,6 +154,7 @@ impl WebTransportSendStream {
events,
session_id,
session,
stream_info: Http3StreamInfo::new(stream_id, Http3StreamType::WebTransport(session_id)),
}
}

Expand All @@ -160,8 +164,8 @@ impl WebTransportSendStream {
self.session.borrow_mut().remove_send_stream(self.stream_id);
}

fn get_info(&self) -> Http3StreamInfo {
Http3StreamInfo::new(self.stream_id, self.stream_type())
const fn get_info(&self) -> &Http3StreamInfo {
&self.stream_info
}
}

Expand Down
10 changes: 5 additions & 5 deletions neqo-http3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,14 +544,14 @@ impl Http3StreamInfo {
}

trait RecvStreamEvents: Debug {
fn data_readable(&self, _stream_info: Http3StreamInfo) {}
fn recv_closed(&self, _stream_info: Http3StreamInfo, _close_type: CloseType) {}
fn data_readable(&self, _stream_info: &Http3StreamInfo) {}
fn recv_closed(&self, _stream_info: &Http3StreamInfo, _close_type: CloseType) {}
}

trait HttpRecvStreamEvents: RecvStreamEvents {
fn header_ready(
&self,
stream_info: Http3StreamInfo,
stream_info: &Http3StreamInfo,
headers: Vec<Header>,
interim: bool,
fin: bool,
Expand Down Expand Up @@ -623,8 +623,8 @@ trait HttpSendStream: SendStream {
}

trait SendStreamEvents: Debug {
fn send_closed(&self, _stream_info: Http3StreamInfo, _close_type: CloseType) {}
fn data_writable(&self, _stream_info: Http3StreamInfo) {}
fn send_closed(&self, _stream_info: &Http3StreamInfo, _close_type: CloseType) {}
fn data_writable(&self, _stream_info: &Http3StreamInfo) {}
}

/// This enum is used to mark a different type of closing a stream:
Expand Down
6 changes: 3 additions & 3 deletions neqo-http3/src/push_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ impl RecvPushEvents {
}

impl RecvStreamEvents for RecvPushEvents {
fn data_readable(&self, _stream_info: Http3StreamInfo) {
fn data_readable(&self, _stream_info: &Http3StreamInfo) {
self.push_handler.borrow_mut().new_stream_event(
self.push_id,
Http3ClientEvent::PushDataReadable {
Expand All @@ -472,7 +472,7 @@ impl RecvStreamEvents for RecvPushEvents {
);
}

fn recv_closed(&self, _stream_info: Http3StreamInfo, close_type: CloseType) {
fn recv_closed(&self, _stream_info: &Http3StreamInfo, close_type: CloseType) {
match close_type {
CloseType::ResetApp(_) => {}
CloseType::ResetRemote(_) | CloseType::LocalError(_) => self
Expand All @@ -487,7 +487,7 @@ impl RecvStreamEvents for RecvPushEvents {
impl HttpRecvStreamEvents for RecvPushEvents {
fn header_ready(
&self,
_stream_info: Http3StreamInfo,
_stream_info: &Http3StreamInfo,
headers: Vec<Header>,
interim: bool,
fin: bool,
Expand Down
6 changes: 4 additions & 2 deletions neqo-http3/src/recv_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub struct RecvMessage {
stream_id: StreamId,
priority_handler: PriorityHandler,
blocked_push_promise: VecDeque<PushInfo>,
stream_info: Http3StreamInfo,
}

impl Display for RecvMessage {
Expand Down Expand Up @@ -113,6 +114,7 @@ impl RecvMessage {
stream_id: message_info.stream_id,
priority_handler,
blocked_push_promise: VecDeque::new(),
stream_info: Http3StreamInfo::new(message_info.stream_id, Http3StreamType::Http),
}
}

Expand Down Expand Up @@ -365,8 +367,8 @@ impl RecvMessage {
)
}

const fn get_stream_info(&self) -> Http3StreamInfo {
Http3StreamInfo::new(self.stream_id, Http3StreamType::Http)
const fn get_stream_info(&self) -> &Http3StreamInfo {
&self.stream_info
}
}

Expand Down
6 changes: 4 additions & 2 deletions neqo-http3/src/send_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub struct SendMessage {
stream: BufferedStream,
encoder: Rc<RefCell<QPackEncoder>>,
conn_events: Box<dyn SendStreamEvents>,
stream_info: Http3StreamInfo,
}

impl SendMessage {
Expand All @@ -133,6 +134,7 @@ impl SendMessage {
stream: BufferedStream::new(stream_id),
encoder,
conn_events,
stream_info: Http3StreamInfo::new(stream_id, stream_type),
}
}

Expand Down Expand Up @@ -160,8 +162,8 @@ impl SendMessage {
Option::<StreamId>::from(&self.stream).expect("stream has ID")
}

fn get_stream_info(&self) -> Http3StreamInfo {
Http3StreamInfo::new(self.stream_id(), Http3StreamType::Http)
const fn get_stream_info(&self) -> &Http3StreamInfo {
&self.stream_info
}
}

Expand Down
Loading
Loading