Skip to content

perf: avoid reallocating the read buffer to watch for EOF - #4216

Open
dancixx wants to merge 1 commit into
hyperium:masterfrom
dancixx:perf-eof-read-no-realloc
Open

dancixx wants to merge 1 commit into
hyperium:masterfrom
dancixx:perf-eof-read-no-realloc

Conversation

@dancixx

@dancixx dancixx commented Oct 1, 2026

Copy link
Copy Markdown

The EOF check that runs while a request is in flight (mid_message_detect_eof → force_io_read) reserves a full 8 KiB read chunk whenever the spare capacity is smaller, which it always is right after a head was split off. The head still shares the buffer, so every request allocates a new one when the service holds on to the request (axum does).

This reads into the existing spare capacity instead and only grows a full buffer.

axum hello world: 14 → 12 allocations and 9,280 → 1,048 bytes per request. The added test fails without the change.

@dancixx
dancixx force-pushed the perf-eof-read-no-realloc branch 2 times, most recently from 9048c62 to d197a2d Compare October 1, 2026 07:35
@dancixx dancixx changed the title perf(http1): avoid reallocating the read buffer to watch for EOF perf: avoid reallocating the read buffer to watch for EOF Oct 1, 2026
Comment thread src/proto/h1/io.rs Outdated
fn poll_read_from_io_inner(
&mut self,
cx: &mut Context<'_>,
grow: bool,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I find boolean arguments to be rather confusing at the call site. A custom 2-variant enum is likely always clearer.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

moved to enum

@dancixx
dancixx force-pushed the perf-eof-read-no-realloc branch from d197a2d to 13b783b Compare October 1, 2026 19:04
@dancixx
dancixx force-pushed the perf-eof-read-no-realloc branch from 13b783b to c2a7377 Compare October 1, 2026 19:08

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants