Skip to content

Defer DRC drops in host-side write_gc_ref#13842

Open
alexcrichton wants to merge 1 commit into
bytecodealliance:mainfrom
alexcrichton:drc-defer-drop
Open

Defer DRC drops in host-side write_gc_ref#13842
alexcrichton wants to merge 1 commit into
bytecodealliance:mainfrom
alexcrichton:drc-defer-drop

Conversation

@alexcrichton

Copy link
Copy Markdown
Member

This commit is an update to the DRC collector to avoid immediately dropping GC references in write_gc_ref. This is done today by threading contextual information such as ExternRefHostDataTable all the way down to write_gc_ref and drop_gc_ref hooks, but a refactoring that I'm planning to do is going to make it significantly more complicated to thread all necessary contextual information through to these hooks. Specifically I'm hoping to store TraceInfo outside of stores and instead inside of Module and RegisteredType to avoid the need for per-type work done during module instantiation. Threading this context through these hooks is effectively ergonomically a no-go.

The strategy then taken in this commit is to change the DRC allocator, the only allocator we have that needs this information during these barriers. The DRC allocator now defers full deallocation of GC allocations to a later point in time where contextual information is available (e.g. during a GC itself). This means that host-initiated writes/drops are no longer guaranteed to actually run destructors immediately (same as with the copying collector). Internally the DRC heap already has a stack of references to decrement, and previously it was only needed during a decrement operation and now it's instead modified to persist between GC barriers through to a GC itself.

This commit is an update to the DRC collector to avoid immediately
dropping GC references in `write_gc_ref`. This is done today by
threading contextual information such as `ExternRefHostDataTable` all
the way down to `write_gc_ref` and `drop_gc_ref` hooks, but a
refactoring that I'm planning to do is going to make it significantly
more complicated to thread all necessary contextual information through
to these hooks. Specifically I'm hoping to store `TraceInfo` outside of
stores and instead inside of `Module` and `RegisteredType` to avoid the
need for per-type work done during module instantiation. Threading this
context through these hooks is effectively ergonomically a no-go.

The strategy then taken in this commit is to change the DRC allocator,
the only allocator we have that needs this information during these
barriers. The DRC allocator now defers full deallocation of GC
allocations to a later point in time where contextual information is
available (e.g. during a GC itself). This means that host-initiated
writes/drops are no longer guaranteed to actually run destructors
immediately (same as with the copying collector). Internally the DRC
heap already has a stack of references to decrement, and previously it
was only needed during a decrement operation and now it's instead
modified to persist between GC barriers through to a GC itself.
@alexcrichton alexcrichton requested a review from fitzgen July 7, 2026 20:54
@alexcrichton alexcrichton requested a review from a team as a code owner July 7, 2026 20:54
@github-actions github-actions Bot added wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:ref-types Issues related to reference types and GC in Wasmtime labels Jul 7, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Subscribe to Label Action

cc @fitzgen

Details This issue or pull request has been labeled: "wasmtime:api", "wasmtime:ref-types"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: wasmtime:ref-types

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:ref-types Issues related to reference types and GC in Wasmtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant