Improve auto WriteStrategy with writev heuristic
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.3k
- Forks
- 1.8k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 14
Description
The default write strategy for HTTP/1 in hyper is to automatically to chose the "best" option. Currently, it simply determines the best based on if AsyncWrite::is_write_vectored(). However, depending on if the response bodies are usually big or usually small, flatten or queue might be better.
The suggested improvement here is:
- Determine a best-guess size for when bodies smaller than N should prefer
Flatten. Make it a constant and document how the number was determined. - In
proto/h1/io.rs:- Add an
Autovariant toWriteStrategy, and default to it. If the user has specified a strategy, the default will be overridden already.- If the underlying IO doesn't support vectored writes, set the strategy to
Flatten.
- If the underlying IO doesn't support vectored writes, set the strategy to
- In
WriteBuf::buffer(), if the strategy isAuto, check if the buffer size is less than the defined constant. If it is smaller, then change the strategy toFlatten, otherwise change it toQueue.
- Add an
There's no need for any public API changes.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in proto/h1/io.rs by reading WriteStrategy and WriteBuf::buffer(), then trace how the current automatic strategy is selected and how buffering records its size. Define and document the small-body threshold, add the Auto behavior and default, and verify that unsupported vectored writes use Flatten while larger buffers use Queue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend-api-design, networking
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100