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

PHP: Replace Worker Threads with Web Workers #471

Merged
merged 3 commits into from
Jun 19, 2023

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented May 30, 2023

Description

Iframe worker threads were introduced as a workaround for limitations in web browsers. Namely:

  • Chrome crashed when using WASM in web workers
  • Firefox didn't support ESM workers at all

Both problems are now solved:

There are no more reasons to keep maintaining the iframe worker thread backend. Let's remove it and lean fully on web workers.

Breaking change

This PR changes the signature of spawnPHPWorkerThread from spawnPHPWorkerThread(workerUrl, workerType, options) to spawnPHPWorkerThread(workerUrl, options) and is therefore breaking. The following follow-up PR is required:

WordPress/playground-tools#81

cc @eliot-akira

@eliot-akira
Copy link
Collaborator

eliot-akira commented May 30, 2023

Happen to have running Firefox 113, just before ESM module import in workers was supported, because apparently the update to 114 hasn't reached this distribution yet. Checked out the PR branch, and the built static site (dist/packages/playground/wasm-wordpress-net) runs fine on both FF 113 and Firefox Nightly which is at version 115. (Not sure why it's working on the older version - may have enabled an experimental flag under about:config.) It's refreshing to see a PR that removes code and complexity.

adamziel added 3 commits June 19, 2023 09:58
Iframe worker threads were introduced as a workaround for limitations in
web browsers. Namely:

* Chrome crashed when using WASM in web workers
* Firefox didn't support ESM workers at all

Both problems are now solved:

* #1
* mdn/content#26774

There are no more reasons to keep maintaining the iframe worker thread
backend. Let's remove it and lean fully on web workers.
@adamziel adamziel force-pushed the remove-worker-thread-concept branch from 80b8386 to 883ba6d Compare June 19, 2023 08:01
adamziel added a commit to WordPress/playground-tools that referenced this pull request Jun 19, 2023
Adjusts the interactive code block to use the new `spawnPHPWorkerThread()` signature committed in WordPress/wordpress-playground#471

The old signature was `spawnPHPWorkerThread(url, workerType, options)`

The new signature is `spawnPHPWorkerThread(url, options)` as WASM in ESM WebWorkers is now correctly supported in all major browser.
@adamziel adamziel merged commit c7b7378 into trunk Jun 19, 2023
@adamziel adamziel deleted the remove-worker-thread-concept branch June 19, 2023 08:39
sejas pushed a commit to WordPress/playground-tools that referenced this pull request Jun 21, 2023
* Adjusts the interactive code block to use the new `spawnPHPWorkerThread()` signature committed in WordPress/wordpress-playground#471
* The old signature was `spawnPHPWorkerThread(url, workerType, options)`
* The new signature is `spawnPHPWorkerThread(url, options)` as WASM in ESM
WebWorkers is now correctly supported in all major browser.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants