hyperium / hyperium/hyper

Improve auto WriteStrategy with writev heuristic

Open
#2,910 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-http1 C-performance E-medium
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 Auto variant to WriteStrategy, 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.
    • In WriteBuf::buffer(), if the strategy is Auto, check if the buffer size is less than the defined constant. If it is smaller, then change the strategy to Flatten, otherwise change it to Queue.

There's no need for any public API changes.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.