h2 icon indicating copy to clipboard operation
h2 copied to clipboard

Remove futures-util dependency

Open jplatte opened this issue 4 years ago • 7 comments

h2 currently depends on futures-util, which is rather heavy (containing heaps of combinators, plus pulling in most of the other futures-* crates) for only two things: poll_fn and AtomicWaker. poll_fn could trivially be copy-pasted (and is also coming to std so eventually that could be used), but the same thing is not true for AtomicWaker. I am not really familiar with the details of wakers, so don't really know how feasible it is to replace that / whether there's maybe an equivalent in tokio / tokio-utils.

I hope there is some new info in this issue. If somebody knows about a good replacement for futures-util's AtomicWaker, I'd be happy to create a PR removing the futures-util dependency.

jplatte avatar Jan 07 '21 20:01 jplatte

This might be a good replacement https://crates.io/crates/atomic-waker, although very few crates seem to be using it. A better option might be to disable as many features as possible in imports for futures-util, which h2 is already doing by disabling all default features.

paolobarbolini avatar Jan 07 '21 21:01 paolobarbolini

Oh hey, that's literally

futures::task::AtomicWaker extracted into its own crate.

Also, it's owned by smol-rs, so maintained by reputable folks.

@carllerche @seanmonstar wdyt? Would a PR replacing futures-util by atomic-waker + a copy-pasted std::future::poll_fn be welcome?

jplatte avatar Jan 07 '21 21:01 jplatte

heavy

Is this still a problem even if the next version of futures-util is released? (https://github.com/rust-lang/futures-rs/pull/2273) If it can solve the problem, I can publish it.

(Also, note that relying on atomic-waker crate will eventually increase compile time, even if the compile time of h2 alone is shortened.)

taiki-e avatar Jan 08 '21 02:01 taiki-e

fyi https://github.com/rust-lang/futures-rs/pull/2307

taiki-e avatar Jan 08 '21 03:01 taiki-e

I think we can close this as futures-util 0.3.9 has been released. (All of the main users of this crate seem to depend on futures-util, so adding a dependency like atomic-waker will only increase their compile time.)

taiki-e avatar Jan 08 '21 04:01 taiki-e

I don't think so. Yes, you reduced the dependencies of futures-util which is pretty nice, but futures-util itself takes almost 4s to compile, before and after, in your own benchmark. Also, h2 still depends on pin-project (through tracing-futures) although on an old version, so it probably benefits some by only having a dependency to one version of it now.

You are right about many reverse dependencies of h2 (including hyper, hyper-rustls, reqwest) also depending on futures-util. I will look into whether they use equally small portions of it and try to follow up on their respective issue trackers if that is the case. I'll close this issue if it turns out to not be feasible to remove it from those projects.

Feel free to ping me on any relates issues on rust-lang/futures-rs 🙂

jplatte avatar Jan 08 '21 14:01 jplatte

I looked into it, since I also use hyper-rustls, and I was able to send this PR to completely remove futures-util https://github.com/ctz/hyper-rustls/pull/142

paolobarbolini avatar Jan 08 '21 17:01 paolobarbolini