HeadlinesBriefing favicon HeadlinesBriefing.com

Rust compiler tweak targets async binary bloat

Hacker News •
×

Developer behind a recent blog series is pushing for a compiler‑level fix to async‑related binary bloat. While async Rust lets code run on servers and microcontrollers alike, the generated state machines inflate firmware size, a problem that shows up starkly on constrained devices. The author has filed a Project Goal on the Rust open-source repository and is seeking funding to implement the changes.

To illustrate the issue, the post compares two simple async functions. The compiler emits 360 lines of MIR for a function with two awaits, versus just 23 lines for its synchronous counterpart. The generated CoroutineLayout includes Unresumed, Returned and Panicked states, the latter causing a panic on any poll after completion, which the author argues is unnecessary overhead, a significant drawback.

By removing the panic path and collapsing trivial states, the author measured a 2%-5% reduction in binary size for embedded firmware and a modest 0.2% gain on a simple future. LLVM’s optimizer can’t always eliminate these patterns, especially at lower opt levels, so compiler‑side simplifications are needed. The proposal suggests a release‑only switch, mirroring existing overflow‑check controls, and would be practically beneficial.