Skip to content
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

Web: implement WaitUntilStrategy #3739

Merged
merged 2 commits into from
Jun 20, 2024

Conversation

daxpedda
Copy link
Member

This implements an alternative scheduling strategy for ControlFlow::WaitUntil on Web to prevent throttling when the tab is not focused by using a worker, which commonly browsers don't throttle regardless of tab focus.

I also added another step to the CI to add JS minification, let me know if you want me to remove it.

Fixes #3738.

@@ -0,0 +1,10 @@
onmessage = event => {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I'm confused as to why this is in JavaScript? Is it not possible to write the worker in Rust? Or is it because it'd require a cumbersome build.rs step or similar to first compile the Rust code to WASM, and then embed that WASM into the final application?

(I'm totally fine with this being JS either way, mostly just curious).

Copy link
Member Author

@daxpedda daxpedda Jun 20, 2024

Choose a reason for hiding this comment

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

Unfortunately its currently impossible to spawn a worker without at least some JS.
Even the current plan of the Shared Everything Threads Proposal requires a polyfill written in JS to make it work.

In any case, until the component model is stable and integrated a lot of functionality currently requires JS anyway, its just that it is something wasm-bindgen usually takes care of. However spawning workers unfortunately isn't one of those things.

I was briefly considering waiting until I release my web-thread crate, but realized that it would require a custom JS solution for single-threaded Wasm anyway, so this works for both.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
@daxpedda daxpedda merged commit 3e6092b into rust-windowing:master Jun 20, 2024
53 checks passed
daxpedda added a commit that referenced this pull request Jun 20, 2024
kchibisov pushed a commit that referenced this pull request Jun 21, 2024
kchibisov pushed a commit that referenced this pull request Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

Web: alternative strategy for ControlFlow::WaitUntil
2 participants