rust: box some futures in callers#1945
Open
benma wants to merge 2 commits into
Open
Conversation
NickeZ
approved these changes
Apr 21, 2026
Reduces binary size by ~1360b. async fn lowers to a concrete state-machine type. In a function like signtx::_process() in src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs, every directly-awaited child future becomes part of that parent future’s stored state. If the child is large, the parent future gets larger too, and its generated poll() logic has to handle that larger layout. Box::pin(child()).await changes the shape of the parent future: - The child future is still a concrete type. - But the parent no longer stores that full child state inline. - It stores a boxed pointer instead. - So the parent future becomes smaller and simpler.
The top-level HWW API dispatch function builds one large async state machine that has to cover every request variant. That keeps all of the branch-specific future layouts live in a single monomorphized type and costs a noticeable amount of ROM. Change the top-level dispatch helpers to return boxed futures and box each branch individually. This moves the size cost from code generation into a small runtime allocation at dispatch time, while leaving the API surface and request handling behavior unchanged. Saves 1832 bytes in firmware.bin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reduces binary size by ~1360b.
async fn lowers to a concrete state-machine type. In a function like signtx::_process() in src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs, every directly-awaited child future becomes part of that parent
future’s stored state. If the child is large, the parent future gets larger too, and its generated poll() logic has to handle that larger layout.
Box::pin(child()).await changes the shape of the parent future: