Skip to content

Commit

Permalink
perf(bin/server): increase msg size and don't allocate msg per resp (#…
Browse files Browse the repository at this point in the history
…1772)

* perf(bin/server): increase msg size and don't allocate msg per resp

Previously `neqo-server` would respond to a request by repeatedly sending a
static 440 byte message (Major-General's Song). Instead of sending 440 bytes,
increase the batch size to 4096 bytes. This also matches the `neqo-client`
receive buffer size.

https://github.com/mozilla/neqo/blob/76630a5ebb6c6b94de6a40cf3f439b9a846f6ab7/neqo-bin/src/bin/client/http3.rs#L165

Previously `ResponseData::repeat` would convert the provided `buf: &[u8]` to `
Vec<u8>`, i.e. re-allocate the buf. Instead keep a reference to the original
buf, thus removing the allocation.

* Remove unnecessary into()
  • Loading branch information
mxinden authored Mar 27, 2024
1 parent 37be894 commit 6a51a35
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions neqo-bin/src/bin/server/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// except according to those terms.

use std::{
borrow::Cow,
cell::RefCell,
cmp::min,
collections::HashMap,
Expand Down Expand Up @@ -196,7 +197,7 @@ trait HttpServer: Display {
}

struct ResponseData {
data: Vec<u8>,
data: Cow<'static, [u8]>,
offset: usize,
remaining: usize,
}
Expand All @@ -211,17 +212,17 @@ impl From<Vec<u8>> for ResponseData {
fn from(data: Vec<u8>) -> Self {
let remaining = data.len();
Self {
data,
data: Cow::Owned(data),
offset: 0,
remaining,
}
}
}

impl ResponseData {
fn repeat(buf: &[u8], total: usize) -> Self {
fn repeat(buf: &'static [u8], total: usize) -> Self {
Self {
data: buf.to_owned(),
data: Cow::Borrowed(buf),
offset: 0,
remaining: total,
}
Expand Down Expand Up @@ -260,14 +261,7 @@ struct SimpleServer {
}

impl SimpleServer {
const MESSAGE: &'static [u8] = b"I am the very model of a modern Major-General,\n\
I've information vegetable, animal, and mineral,\n\
I know the kings of England, and I quote the fights historical\n\
From Marathon to Waterloo, in order categorical;\n\
I'm very well acquainted, too, with matters mathematical,\n\
I understand equations, both the simple and quadratical,\n\
About binomial theorem, I'm teeming with a lot o' news,\n\
With many cheerful facts about the square of the hypotenuse.\n";
const MESSAGE: &'static [u8] = &[0; 4096];

pub fn new(
args: &Args,
Expand Down

0 comments on commit 6a51a35

Please sign in to comment.