return more data at once from TlsStream::poll_read - #198
Open
trinity-1686a wants to merge 3 commits into
Open
Conversation
this can improve the performance of some consumers, notably Hyper
djc
approved these changes
Sep 1, 2026
| let len = data.len().min(buf.remaining()); | ||
| buf.put_slice(&data[..len]); | ||
| self.consume(len); | ||
| if len > 0 { |
Member
There was a problem hiding this comment.
Nit: suggest flipping this with an early return, to reduce rightward drift.
| Poll::Ready(Err(_)) => break, // non-transient error gets re-emitted next poll | ||
| Poll::Pending => break, | ||
| }; | ||
| let len = data.len().min(buf.remaining()); |
Member
There was a problem hiding this comment.
Nit: using a symmetric min() like Ord::min() makes this easier to follow IMO.
Member
|
Would be cool to also do this for the server side. |
trinity-1686a
force-pushed
the
hyper-perf
branch
from
September 1, 2026 20:21
136c31f to
40cdf85
Compare
Author
|
i've confirmed the effect on the read path of the server. i should also add because it bite me while trying to assess performance on the server half that, in hyper, this only impacts http1, h2 there seem to use much smaller buffers so that results are largely within the variance of my setup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using Hyper with tokio-rustls, and streaming a response body, hyper only emits blocks of 16k (a single TLS record), even when hyper uses a larger receive buffer. This causes more wake-ups for hyper callers, and generally more work inside hyper itself.
This PR makes it so TlsStream::poll_read tries to return more data at once, which measurably improves Hyper's performance over TLS streams.
I assume there is a similar gain on the server side with requests that have a large body (instead of response having a body for client), though i haven't attempted to measure or fix that yet.
very simple (but noisy) bench setup:
running a slightly simplified version of this example (commenting out
to_bytes()and actual printing of the body, to make the gain more visible), and runningperf stat ./target/release/examples/client https://proof.ovh.net/files/1Gb.dat(download 1GiB from a remote server), i getWhile this could also be a change in hyper to call poll_read() until it returns Pending, i think other consumers of rustls could have the same inefficiency, and this is better handled at that level.