add monotonic clock "pause" feature to p1->p2 adapter#13563
Merged
alexcrichton merged 1 commit intoJun 5, 2026
Conversation
This adds a new `adapter_monotonic_clock_set_paused` export to the adapter which toggles whether `clock_time_get` will call `monotonic_clock::now` when called with `CLOCKID_MONOTONIC` versus returning a cached value instead. This is a workaround for guest language runtimes whose `cabi_realloc` implementations may call `clock_time_get`. Since calling imports from `cabi_realloc` is disallowed, this will trap if the adapter calls `monotonic_clock::now`. We can avoid the trap by using a cached value instead. This helps us address bytecodealliance/componentize-go#56. In that case, `cabi_realloc` is implemented by calling [unsafe.SliceData](https://pkg.go.dev/unsafe#SliceData) to allocate a segment of the appropriate size and alignment from the GC-managed heap and then pinning it using [pinner.Pin](https://pkg.go.dev/runtime#Pinner.Pin) until it is no longer needed. However, such an allocation may trigger a GC under memory pressure, and as of this writing the Go collector calls `clock_time_get` to measure time spent in various stages of the GC process. An alternative fix for the `componentize-go` issue would be to modify the Go runtime to avoid such calls on WASI during GC, but getting that upstream is likely to be significantly more difficult than working around it in the adapter. If and when Go supports WASIp3 or later natively, the adapter will no longer be used, in which case we will certainly address this upstream.
alexcrichton
approved these changes
Jun 4, 2026
Member
alexcrichton
left a comment
There was a problem hiding this comment.
I'm not thrilled about it, but I suspect you aren't either, and so long as Go is an unchangable monolith I don't think there are many other realistic options on the table.
dicej
added a commit
to dicej/go-pkg
that referenced
this pull request
Jun 5, 2026
See bytecodealliance/wasmtime#13563 for details and note that this will require using an up-to-date (and currently not-yet-released) version of the `wasi_snapshot_preview1` adapter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a new
adapter_monotonic_clock_set_pausedexport to the adapter which toggles whetherclock_time_getwill callmonotonic_clock::nowwhen called withCLOCKID_MONOTONICversus returning a cached value instead.This is a workaround for guest language runtimes whose
cabi_reallocimplementations may callclock_time_get. Since calling imports fromcabi_reallocis disallowed, this will trap if the adapter callsmonotonic_clock::now. We can avoid the trap by using a cached value instead.This helps us address
bytecodealliance/componentize-go#56. In that case,
cabi_reallocis implemented by callingunsafe.SliceData to allocate a segment of the appropriate size and alignment from the GC-managed heap and then pinning it using pinner.Pin until it is no longer needed. However, such an allocation may trigger a GC under memory pressure, and as of this writing the Go collector calls
clock_time_getto measure time spent in various stages of the GC process.An alternative fix for the
componentize-goissue would be to modify the Go runtime to avoid such calls on WASI during GC, but getting that upstream is likely to be significantly more difficult than working around it in the adapter. If and when Go supports WASIp3 or later natively, the adapter will no longer be used, in which case we will certainly address this upstream.