Skip to content
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

refactor(server): remove needless clone in ws background task #1203

Merged
merged 1 commit into from
Sep 15, 2023
Merged
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
18 changes: 6 additions & 12 deletions server/src/transport/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(crate) struct Batch<'a, L: Logger> {
#[derive(Debug, Clone)]
pub(crate) struct CallData<'a, L: Logger> {
pub(crate) conn_id: usize,
pub(crate) bounded_subscriptions: BoundedSubscriptions,
pub(crate) bounded_subscriptions: &'a BoundedSubscriptions,
pub(crate) id_provider: &'a dyn IdProvider,
pub(crate) methods: &'a Methods,
pub(crate) max_response_body_size: u32,
Expand Down Expand Up @@ -266,6 +266,7 @@ pub(crate) async fn background_task<L: Logger>(sender: Sender, mut receiver: Rec
sink: sink.clone(),
id_provider,
logger: logger.clone(),
bounded_subscriptions,
});

tokio::pin!(stopped);
Expand Down Expand Up @@ -319,11 +320,7 @@ pub(crate) async fn background_task<L: Logger>(sender: Sender, mut receiver: Rec
}
};

pending_calls.push(tokio::spawn(execute_unchecked_call(
params.clone(),
std::mem::take(&mut data),
bounded_subscriptions.clone(),
)));
pending_calls.push(tokio::spawn(execute_unchecked_call(params.clone(), std::mem::take(&mut data))));
};

// Drive all running methods to completion.
Expand Down Expand Up @@ -492,18 +489,15 @@ struct ExecuteCallParams<L: Logger> {
max_log_length: u32,
sink: MethodSink,
logger: L,
bounded_subscriptions: BoundedSubscriptions,
}

async fn execute_unchecked_call<L: Logger>(
params: Arc<ExecuteCallParams<L>>,
data: Vec<u8>,
bounded_subscriptions: BoundedSubscriptions,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch 👍

Would be interesting to see how big the performance improvement is, since I would expect the BoundedSubscriptions clone to be cheap (contains an Arc<..> and a u64)

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, shouldn't matter in practice but found it when I was debugging stuff :P

) {
async fn execute_unchecked_call<L: Logger>(params: Arc<ExecuteCallParams<L>>, data: Vec<u8>) {
let request_start = params.logger.on_request(TransportProtocol::WebSocket);
let first_non_whitespace = data.iter().enumerate().take(128).find(|(_, byte)| !byte.is_ascii_whitespace());

let call_data = CallData {
bounded_subscriptions,
bounded_subscriptions: &params.bounded_subscriptions,
conn_id: params.conn_id as usize,
max_response_body_size: params.max_response_body_size,
max_log_length: params.max_log_length,
Expand Down
Loading