Stream: git-wasmtime

Topic: wasmtime / PR #7282 Gate many CLI/Wasmtime features behin...


view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 17:12):

alexcrichton requested fitzgen for a review on PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 17:12):

alexcrichton requested wasmtime-core-reviewers for a review on PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 17:12):

alexcrichton requested wasmtime-default-reviewers for a review on PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 17:12):

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 the wasmtime-cli crate to disable functionality up to and including wasmtime compile for example. This PR enables building a wasmtime 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 for addr2line 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 the wasmtime 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 as clap 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.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 17:42):

fitzgen submitted PR review:

Looks great to me, the new page in the guide looks great as well.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 17:42):

fitzgen submitted PR review:

Looks great to me, the new page in the guide looks great as well.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 17:42):

fitzgen created PR review comment:

Should probably specify the architecture as well.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 17:42):

fitzgen created PR review comment:

Maybe name this disable-logging?

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 17:42):

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 cfgs and all that.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 18:20):

alexcrichton updated PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 18:20):

alexcrichton updated PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 18:22):

alexcrichton updated PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 18:33):

alexcrichton has enabled auto merge for PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 18:33):

alexcrichton has disabled auto merge for PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 18:34):

bjorn3 submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 18:34):

bjorn3 created PR review comment:

Stripping debuginfo using -Cstrip=debuginfo should also help a fair bit, right?

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 19:16):

alexcrichton updated PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 19:24):

alexcrichton updated PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 19:25):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 19:25):

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

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 19:25):

alexcrichton has enabled auto merge for PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 19:42):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 19:42):

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")

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 20:14):

alexcrichton updated PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 20:14):

alexcrichton has enabled auto merge for PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 21:16):

alexcrichton updated PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 21:16):

alexcrichton has enabled auto merge for PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 23:21):

abrown submitted PR review:

Nice work documenting the pruning! I've always sort of wondered what the minimum size would be.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 19 2023 at 15:44):

alexcrichton updated PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 19 2023 at 15:44):

alexcrichton has enabled auto merge for PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 19 2023 at 17:22):

alexcrichton updated PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 19 2023 at 17:22):

alexcrichton has enabled auto merge for PR #7282.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 19 2023 at 18:53):

alexcrichton merged PR #7282.


Last updated: Dec 23 2024 at 12:05 UTC