chore: slim the futures facade dependency - #663
Conversation
Both APIs are stable in the pinned 1.95 toolchain, so the ten call
sites that reached for `futures::task::noop_waker{,_ref}` and
`futures::pin_mut!` now use std directly.
Refs #596
`core` boxes its recast future with std types. `eth2api` and `cluster` take their `Stream`/`StreamExt` from `tokio-stream`, whose `Stream` is the same `futures_core` trait, so `event_stream`'s public signature is unchanged. Refs #596
| }; | ||
|
|
||
| type RecastFuture = BoxFuture<'static, Result<()>>; | ||
| type RecastFuture = Pin<Box<dyn Future<Output = Result<()>> + Send>>; |
There was a problem hiding this comment.
Why inline rather than keep BoxFuture. This alias was the only thing core used futures for, so spelling it out drops the dependency from the workspace's most-depended-on crate. app's node/wire.rs already defines a SyncBoxFuture alias this way.
| ) -> Result<(Stream, PeerInfo), Failure> { | ||
| let send = protocol.send_peer_info(stream, &request); | ||
| futures::pin_mut!(send); | ||
| let send = std::pin::pin!(protocol.send_peer_info(stream, &request)); |
There was a problem hiding this comment.
No mut needed here, unlike the other two pin! sites. futures::pin_mut! expands to let mut $x = ... unconditionally. future::select takes the pinned future by value, so a plain binding is enough.
The two sites that poll in a loop — app/src/sse/mod.rs and this crate's sibling in eth2api — do need let mut, since StreamExt::next borrows &mut self.
emlautarom1
left a comment
There was a problem hiding this comment.
Very quick refactor, drops some dependencies in the Cargo.toml files.
Closes #596
Summary
core,eth2apiandclusterno longer depend on thefuturesfacade, and ten call sites move tostd::task::Waker::noop/std::pin::pin!.This does not slim the build graph
The
Cargo.lockdiff is 2 insertions / 3 deletions — only the three crates' dependent lists.futuresis a direct dependency of 20 crates we don't control (libp2pplus 13 of its sub-crates, fouralloycrates,if-watch,rw-stream-sink,yamux,wiremock), and ten Pluto crates still need it.tokio-streamwas already in the graph viap2p.Two suggestions from the issue are unreachable for that reason and are not implemented:
default-features = falsewould not drop the executor.libp2p-coredeclaresfutureswithfeatures = ["executor", "thread-pool"], and cargo unifies features graph-wide.futures-timerfrompeerinfochanges nothing — nine libp2p crates depend on it directly, and it is what libp2p's ownConnectionHandlers use for timeouts.What this buys is manifest honesty: every remaining
futuresdependency is traceable to a libp2p-driven need.Out of scope
join_allstays.JoinSet::join_allreturns results in completion order wherejoin_allpreserves input order, andFuturesUnorderedhas no tokio equivalent.The other ten crates keep
futuresforselect_next_some(app,relay-server),FuturesUnordered(cli), and futures'AsyncRead/AsyncWrite/io::Cursorfor libp2p's protocol APIs (p2p,consensus,peerinfo,parsigex,dkg,priority).