runtime/wasm: add timers and host event wakeups (based on #102) - #107
Draft
cpunion wants to merge 5 commits into
Draft
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
This was referenced Aug 1, 2026
Open
LLGo baseline benchmarks
Program measurements
Core language and compiler benchmarks
Compared only with the latest matching platform in the main series. Warning
|
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.
Depends on #102.
Fork-only staging PR for xgo-dev#2152 (stage C). It is rebuilt directly from the validated B head and avoids CI load on
xgo-dev/llgo; the old upstream xgo-dev#2204 draft remains frozen.Problem
The single-worker wasm runtime can park goroutines, but it has no host event source for time.
time.Sleep, timers, tickers, timeout selects, andAfterFunctherefore cannot suspend one G while allowing the worker to run another G and later resume the timer owner.Implementation
runtime/internal/wasmeventmin-heap with stable timer ordering, Stop/Reset semantics, periodic deadline catch-up, and lazy dispatch.emscripten_sleepfor J32/J64 host wakeups andpoll(NULL, 0, timeout)for default P1. Preserve the explicitLLGO_WASI_THREADS=1backend.time.Now.//go:wasmimportdeclarations to LLVM wasm import attributes. Directive collection remains in the existing package syntax pass, and metadata is carried byssa.Programacross package/cache compilation.EM_INVOKERcontract while retaining the legacy adapter.The compiler directive scanner, SSA metadata, timer queue, scheduler, and host adapters remain separate. This PR introduces no new target or build tag. Static wasm defer dispatch is inherited through #102's W base and is not part of this effective diff.
Semantics covered
One acceptance fixture runs on J32, J64, and P1 and covers wall clock/local zone,
time.Sleep, active/stopped/reset/expired timers, tickers,AfterFunc, and timeoutselect. Existing scheduler normal/deadlock behavior is also re-executed on all three profiles.Validation
All local builds used
GOMAXPROCS=2,GOMEMLIMIT=6GiB,-p=1where applicable, fresh-abuilds, andLLGO_BUILD_CACHE=off. The Ubuntu container had 2 CPUs and a 6 GiB hard memory limit.ssa, and the full nested runtime module pass.wasm timers ok; P1 also passeswasm-tools validate --features alland Wasmtime.-O0and-O3; J64/P1 pass ThinLTO.runtime/internal/wasmeventis 93.9% covered; dispatch and due-event paths are 100% covered. The new directive collection and SSA wasm-import accessors are 100% covered.git diff --checkandgofmtchecks pass.\n- Current heada5305b8eehas 39 passing checks, one expected release-publication skip, and no failures; the PR is clean, mergeable, and has no unresolved review threads.Cost
On Apple M4 Max with
GOMAXPROCS=2, queue Reset+RunDue measures 7.653-8.021 ns/op, 0 B/op, 0 allocs/op across five runs.Against #102 with identical default builds of a scheduler fixture that does not import
time:The representative native binary remains 84,864 B with identical section sizes. The Cortex-M4 ELF is byte-identical at 1,804 B (
text/data/bss = 140/0/10).Independent diff over #102: 25 files, +1100/-84. No previously runnable test is skipped or ignored.