Skip to content

refactor(lib): drop futures-util except in ffi #3890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025

Conversation

hanna-kruppe
Copy link
Contributor

Make hyper usable for h1/h2 and client/server without this heavyweight dependency. It's about 17k lines of code and takes up to 1.7 seconds to compile on my machine, but hyper is only using a tiny fraction of it. Larger applications probably still pull in futures-util by other means, but it's no longer as unavoidable as in the early days of the ecosystem.

To remove futures-util without raising MSRV, I took these steps:

  • When futures-util just re-exports something from its dependencies, use it directly from the source.
  • Inline trivial helpers like poll_unpin that "only" communicate intent a little better but don't save any significant amount of code.
  • Refactor the h2 client code to avoid StreamFuture for the "Client has been dropped" detection -- just poll the mpsc channel directly.
  • Implement a couple of small helpers from scratch when they're straightforward and fit on one screen each. The majority of this is polyfills for standard library APIs that would require a higher MSRV.
  • Use AtomicWaker from the atomic-waker crate, a separately published copy of the futures-util type of the same name. While the two crates are owned by different organizations (smol-rs vs. rust-lang), it's mostly the same people maintaining both copies.

The uses of future-util in hyper's tests/benches/examples and in the ffi module seem much harder to remove entirely, so I did not touch those modules at all.

Make hyper usable for h1/h2 and client/server without this heavyweight
dependency. It's about 17k lines of code and takes up to 1.7 seconds to
compile on my machine, but hyper is only using a tiny fraction of it.
Larger applications probably still pull in futures-util by other means,
but it's no longer as unavoidable as in the early days of the ecosystem.

To remove futures-util without raising MSRV, I took these steps:

* When futures-util just re-exports something from its dependencies,
  use it directly from the source.
* Inline trivial helpers like `poll_unpin` that "only" communicate
  intent a little better but don't save any significant amount of code.
* Refactor the h2 client code to avoid `StreamFuture` for the "Client
  has been dropped" detection -- just poll the mpsc channel directly.
* Implement a couple of small helpers from scratch when they're
  straightforward and fit on one screen each. The majority of this is
  polyfills for standard library APIs that would require a higher MSRV.
* Use `AtomicWaker` from the `atomic-waker` crate, a separately
  published copy of the futures-util type of the same name. While the
  two crates are owned by different organizations (smol-rs vs.
  rust-lang), it's mostly the same people maintaining both copies.

The uses of future-util in hyper's tests/benches/examples and in the
`ffi` module seem much harder to remove entirely, so I did not touch
those modules at all.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not a fan of all these polyfills but I included them for now to show it's possible (and what it costs) to do without MSRV bump. I'd also be happy to bump the MSRV if that's acceptable.

Copy link
Member

@seanmonstar seanmonstar left a comment

Choose a reason for hiding this comment

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

I think all this looks great, thanks so much!

Any other thoughts? I'd be happy to merge this as-is.

@hanna-kruppe
Copy link
Contributor Author

If you're happy with it then I'm happy as well :) Thanks for the quick review!

@seanmonstar seanmonstar merged commit e11b2ad into hyperium:master May 19, 2025
22 checks passed
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