alexcrichton requested fitzgen for a review on PR #7282.
alexcrichton requested wasmtime-core-reviewers for a review on PR #7282.
alexcrichton requested wasmtime-default-reviewers for a review on PR #7282.
alexcrichton opened PR #7282 from alexcrichton:exe-features
to bytecodealliance:main
:
This PR is borne out of discussions from last week's CG meetings about the suitability of Wasmtime in embedded scenarios. One of the primary concerns that arose was the binary size of the Wasmtime engine being too large for these scenarios. In my experience binary size is one aspect of Rust where it doesn't come for free so this aligns with my expectations. That being said I've yet to see a case in Rust where a particular binary footprint couldn't be achieved, hence this PR.
One thing I've noticed is that many folks evaluating Wasmtime seem to look at the size of the
wasmtime
executable itself when performing size comparisons. While this likely doesn't reflect the true size of what a custom embedding would be it's nevertheless an easy comparison that can be made. To that effect I've added a number of Cargo features to thewasmtime-cli
crate to disable functionality up to and includingwasmtime compile
for example. This PR enables building awasmtime
exectuable that is stripped down to the bare bones - all it can do is run precompiled WebAssembly files. That being said it should still be a full-featured runtime at this time where only some optional features such as DWARF processing foraddr2line
are disabled.Additionally in this PR I've added a new chapter to the Wasmtime book about building a minimal build of Wasmtime. This explains not only the existence of the
--no-default-features
build flag but additionally the consequences in terms of functionality and binary size. Furthermore this section additionally directly expands on tips and tricks for building a minimal binary using various Rust compiler flags and nightly features. This section shows how thewasmtime
CLI is 130M in debug mode and the smallest build producable after this PR is 2.1M.The goal of this PR is to get the ball rolling on size-related optimizations, not necessarily be the end-all-be-all. Further optimizations to binary size will likely require more invasive changes about how we develop Wasmtime or similar. For example we may have to lose the relatively rich error information Wasmtime currently has to get the next level of significant win. That being said I'm at least personally lacking a bit in direction for where to go next to optimize. My hope is that by showcasing a much smaller
wasmtime
CLI executable it shows to folks that Wasmtime for these use cases is viable, even if it's not suitable just yet. For example the CLI uses crates such asclap
which won't be present in custom embeddings. Having an actual custom embedding to optimize for will be useful. In lieu of this I plan on continuing to poke to see what we can do.One option as a result of this PR is to build a
wasmtime-lite
executable on CI and upload it to GitHub Actions/Releases as well. I'm not totally convinced that'd be too useful so I haven't done that. Another option though is to add a CI builder which builds a minimal binary and verifies that it doesn't go above a particular threshold to catch regressions in binary size (e.g. if a new feature is added ensure that it can be disabled with--no-default-features
). I've left this for a future PR as well.I should also note that my hope is that when optimizing for binary size it would not hinder the development of Wasmtime anywhere else. In that sense it should ideally be easy for anyone to understand how the conditionally compiled code works and it shouldn't appear as a maze of cfgs to wade through to get things working. While it's definitely more
#[cfg]
than before, I'm particularly interested if folks feel this is too onerous to maintain or burdensome. If so I'd be interested in improving how this is all designed.
fitzgen submitted PR review:
Looks great to me, the new page in the guide looks great as well.
fitzgen submitted PR review:
Looks great to me, the new page in the guide looks great as well.
fitzgen created PR review comment:
Should probably specify the architecture as well.
fitzgen created PR review comment:
Maybe name this
disable-logging
?
fitzgen created PR review comment:
Would be nice to add some empty lines between these variant definitions now that they are getting a bit noisier with all the
cfg
s and all that.
alexcrichton updated PR #7282.
alexcrichton updated PR #7282.
alexcrichton updated PR #7282.
alexcrichton has enabled auto merge for PR #7282.
alexcrichton has disabled auto merge for PR #7282.
bjorn3 submitted PR review.
bjorn3 created PR review comment:
Stripping debuginfo using
-Cstrip=debuginfo
should also help a fair bit, right?
alexcrichton updated PR #7282.
alexcrichton updated PR #7282.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Oh excellent suggestion I forgot about that! Turns out the majority of the win from
-Zbuild-std
was stripping debuginfo
alexcrichton has enabled auto merge for PR #7282.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
I should highlight this as a drive-by change by me (cc @cfallin), but this'll rename
-C enable-pcc
to-C pcc
(most other options omit the "enable" or "disable" to have everything be "if you specify it it's enabled unless you say=n
in which case you're asking to disable it")
alexcrichton updated PR #7282.
alexcrichton has enabled auto merge for PR #7282.
alexcrichton updated PR #7282.
alexcrichton has enabled auto merge for PR #7282.
abrown submitted PR review:
Nice work documenting the pruning! I've always sort of wondered what the minimum size would be.
alexcrichton updated PR #7282.
alexcrichton has enabled auto merge for PR #7282.
alexcrichton updated PR #7282.
alexcrichton has enabled auto merge for PR #7282.
alexcrichton merged PR #7282.
Last updated: Dec 23 2024 at 12:05 UTC