Skip to content

Compact MoonBit async task state storage#1665

Merged
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
peter-jerry-ye:codex/moonbit-task-state-map
Jul 24, 2026
Merged

Compact MoonBit async task state storage#1665
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
peter-jerry-ye:codex/moonbit-task-state-map

Conversation

@peter-jerry-ye

@peter-jerry-ye peter-jerry-ye commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Why

The generated MoonBit WASI P3 async core stored one component task's state across several maps keyed by the same waitable-set handle. Scheduling and wakeup paths therefore repeated the same lookups, while ownership and terminal cleanup were spread across multiple sources of truth.

This cannot be replaced with one global scheduler queue: P3 may have multiple host-driven component tasks alive at the same time, and each task needs an isolated queue and wakeup path.

What changed

  • Store each component task in one ComponentTaskState registry entry.
  • Give each task a compact TaskLane containing its scheduler queue and wakeup state, and let coroutines retain that lane directly.
  • Keep subscriber lookup task-local while consolidating the rest of the task lifecycle state.
  • Retire terminal lanes only after their owned work is gone, breaking active reference-counting cycles.
  • Treat cancellation of an already-completed coroutine as a no-op, so it cannot revive a retired lane.
  • Panic on impossible missing-state paths instead of adding recovery behavior for violated runtime invariants.
  • Extend generated-source assertions and the async primitives runtime fixture for the new lifecycle behavior.

Why this is correct and minimal

The component-task registry is now the single source of truth for task lifecycle state, while TaskLane preserves the per-task isolation required by P3. Coroutines retain only the smaller scheduling lane rather than the full registry entry, and terminal cleanup explicitly disconnects the remaining scheduler ownership once no queued, blocking, or owned coroutine work remains.

The production changes are confined to MoonBit async-core generation. There are no WIT surface changes, stream-buffering changes, new dependencies, or assumptions of tracing GC.

Upstream note

End-to-end WASI HTTP stress testing also encountered pre-existing Wasmtime serve/lifecycle behavior tracked by wasmtime#13345. Those results are unrelated to this change and were not attributed to it.

@peter-jerry-ye
peter-jerry-ye marked this pull request as ready for review July 24, 2026 12:10
@alexcrichton
alexcrichton added this pull request to the merge queue Jul 24, 2026
Merged via the queue into bytecodealliance:main with commit ce2815c Jul 24, 2026
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants