Async Rust never left the MVP state

· coding · Source ↗

TLDR

  • Async Rust’s state machine codegen has significant binary bloat from redundant states and panic paths, with compiler-level fixes proposed via a Rust Project Goal.

Key Takeaways

  • Every async block generates Unresumed, Returned, and Panicked states even for trivially-ready futures like async { 5 }, bloating embedded and wasm binaries.
  • Replacing post-completion panics with Poll::Pending in release builds yielded 2-5% binary size reduction in async embedded firmware.
  • Match arms with identical await types (e.g., send_response(123).await vs send_response(456).await) generate duplicate states; hoisting the match above the single await collapses them.
  • LLVM cannot reliably optimize these patterns away, especially at opt-level=s or when futures nest deeply, so fixes must happen at the MIR pass level.
  • The author has submitted a Rust Project Goal and is seeking funding to implement these optimizations in the compiler.

Hacker News Comment Review

  • Consensus: the title is overstated for the content; the actual optimizations described are concrete and actionable, not a fundamental condemnation of async Rust.
  • The duplicate-state collapse pattern (hoisting match expressions above await points) is available as a manual refactor today, no compiler changes needed.
  • The sync/async code duplication problem is a live pain point; keyword generics and sans-io patterns are the current best mitigations, with no stdlib solution yet.

Notable Comments

  • @_alphageek: flags the match-hoisting refactor as the single easiest win available to any async Rust codebase right now.
  • @diondokter: author clarifies that async trait and closure support are type-system changes, not async machinery improvements, defending the “MVP” framing.

Original | Discuss on HN