alexcrichton requested fitzgen for a review on PR #13842.
alexcrichton opened PR #13842 from alexcrichton:drc-defer-drop to bytecodealliance:main:
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 asExternRefHostDataTableall the way down towrite_gc_refanddrop_gc_refhooks, 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 storeTraceInfooutside of stores and instead inside ofModuleandRegisteredTypeto 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.
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested wasmtime-core-reviewers for a review on PR #13842.
github-actions[bot] added the label wasmtime:api on PR #13842.
github-actions[bot] added the label wasmtime:ref-types on PR #13842.
github-actions[bot] commented on PR #13842:
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 <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
:thumbs_up: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
This would only happen when both we didn't trace anything on the stack and there was som
write_gc_refthat enqueued a GC reference for processing, right? Otherwise thedec_ref_and_maybe_deallocinside the loop would have processed the ones enqueued by the host, because the host can't run GC barriers for this store while we are in this method.What if we didn't call
dec_ref_and_maybe_deallocinside the stack-tracing loop above, and just enqueued them (similar to host writes), and then had a single place where we do thedec_ref_and_maybe_dealloccall to process all the enqueued things at the end? I think that should be more performant and also lets us avoid "special" calls todec_ref_and_maybe_dealloc, consolidating them all into a single call, which is cleaner as well.
alexcrichton updated PR #13842.
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
Sounds good to me, refactored as such now
alexcrichton added PR #13842 Defer DRC drops in host-side write_gc_ref to the merge queue
github-merge-queue[bot] removed PR #13842 Defer DRC drops in host-side write_gc_ref from the merge queue
alexcrichton added PR #13842 Defer DRC drops in host-side write_gc_ref to the merge queue
:check: alexcrichton merged PR #13842.
alexcrichton removed PR #13842 Defer DRC drops in host-side write_gc_ref from the merge queue
Last updated: Jul 29 2026 at 05:03 UTC