Stream: git-wasmtime

Topic: wasmtime / PR #11987 Enable borrowing components and sto...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2025 at 20:36):

alexcrichton requested fitzgen for a review on PR #11987.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2025 at 20:36):

alexcrichton opened PR #11987 from alexcrichton:less-clone to bytecodealliance:main:

This commit adds a new, safe, function to the Instance type for
internal use in Wasmtime which enables simultaneously borrowing the
Component-within-the-Instance as well as the original store at the
same time. This is not possible to do in safe Rust when the store is
mutable and must be implemented with unsafe code.

The motivation for this commit is performance. In https://github.com/bytecodealliance/wasmtime/issues/11974 it was
discovered that the addition of a single Arc::clone was enough to
reduce throughput in the embedding by 20%. While Arc::clone is
generally cheap I can see how a "contended" Arc::clone could get quite
expensive. This particular benchmark was running multiple instances of
the same component across multiple threads which were all doing many
host calls. Each host call, after the refactoring of https://github.com/bytecodealliance/wasmtime/pull/10959, contained
an Arc::clone to the component itself. This in turn led to many
threads constantly incrementing/decrementing the Arc::clone count of
the same Arc instance.

At a high level this clone is not necessary. The component lives within
the store and cannot be mutated/deleted during execution. Safe Rust,
however, forbids access to the component and mutably using the store at
the same time. Thus, this helper function enters the picture. The goal
here is to remove the Arc::clone calls without requiring major surgery
or such to refactor the implementations of various functions throughout
Wasmtime. The unsafe block used to implement this function documents
more rationale as to why this should be safe.

Closes #11974

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2025 at 20:36):

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

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2025 at 20:37):

alexcrichton commented on PR #11987:

Note that this is built on https://github.com/bytecodealliance/wasmtime/pull/11986, so only the second commit is relevant here.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 07 2025 at 18:19):

fitzgen submitted PR review:

Do we have tests that run under MIRI that cover this?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 07 2025 at 18:19):

fitzgen created PR review comment:

        // within a component instance, within a store, to be deallocated or mutated while
        // a store is in use. Consequently it should be safe to simultaneously

view this post on Zulip Wasmtime GitHub notifications bot (Nov 07 2025 at 18:20):

fitzgen submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 07 2025 at 19:35):

alexcrichton updated PR #11987.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 07 2025 at 19:37):

alexcrichton commented on PR #11987:

We do indeed! There are a number of tests in tests/all/pulley.rs run under miri which do host calls which should exercise these paths.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 07 2025 at 19:37):

alexcrichton has enabled auto merge for PR #11987.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 07 2025 at 20:13):

alexcrichton merged PR #11987.


Last updated: Dec 06 2025 at 06:05 UTC