Skip to content

Add epoch interruption to WASM engine for cooperative yielding #32806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 17, 2025

Conversation

benbrandt
Copy link
Member

Prevent extensions from blocking async threads by enabling epoch
interruption with 100ms intervals. Extensions will yield control back to
the executor regularly during Future::poll operations.

Addresses the
discussion
that goes into depth on why this is important when enabling async
support with Wasmtime.

Release Notes:

  • N/A

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jun 16, 2025
@benbrandt benbrandt requested a review from ConradIrwin June 16, 2025 16:09
// Need to do this on some non-async thread to make sure it makes progress regardless
// of if extensions are blocking.
let engine_ref = engine.weak();
thread::spawn(move || {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if there is a more "zed" way of having a way to do work outside the executor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The background executor can run many tasks in parallel, so it should be fine to rely on that (unless I'm missing something)?

Though this also seems ok

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to have the epoch incrementing happen outside the executor, because otherwise, if all your threads are somehow blocked, then the epoch isn't incremented and then the tasks never yield

@benbrandt benbrandt marked this pull request as draft June 16, 2025 17:26
Prevent extensions from blocking async threads by enabling epoch
interruption with 100ms intervals. Extensions will yield control back to
the executor regularly during Future::poll operations.

Addresses the
[discussion](#24515)
that goes into depth on why this is important when enabling async
support with Wasmtime.
@benbrandt benbrandt force-pushed the wasmtime-interruption branch from 43dedd6 to a7826d8 Compare June 17, 2025 10:08
@benbrandt benbrandt marked this pull request as ready for review June 17, 2025 10:09
Switches from spawning a dedicated thread to using a Timer task for WASM
engine epoch interruption, avoiding unnecessary thread overhead while
maintaining the same functionality.
@benbrandt benbrandt force-pushed the wasmtime-interruption branch from a7826d8 to 22d064e Compare June 17, 2025 10:43
@benbrandt benbrandt merged commit acb0210 into main Jun 17, 2025
20 checks passed
@benbrandt benbrandt deleted the wasmtime-interruption branch June 17, 2025 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants