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

[browser][mt] Provide API to start the web workers later #75629

Closed
Tracked by #68162
lambdageek opened this issue Sep 14, 2022 · 2 comments
Closed
Tracked by #68162

[browser][mt] Provide API to start the web workers later #75629

lambdageek opened this issue Sep 14, 2022 · 2 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-VM-threading-mono os-browser Browser variant of arch-wasm
Milestone

Comments

@lambdageek
Copy link
Member

By default we start the web worker pool that will host pthreads at app startup and wait for each worker to finish loading.
Compared to single threaded apps, this increased page load times.

Starting the worker pool at startup was reasonable because we just used Emscripten's worker startup code. But eventually we ended up overriding that startup sequence with our own code so that we could set up resources on the workers, transfer the MonoConfig, etc.

The upshot is that since we control the worker creation now, we don't have to do it when Emscripten used to. We can give app frameworks more control.

For example, we can provide a mechanism for the application (or the app framework) to start up the threadpool at a later time once the initial page is done loading. We could have an API like:

   namespace System.Runtime.InteropServices.JavaScript;

   public class Threading {
      // returns number of workers that were actually started
      public static Task<int> CreatePThreadWebWorkerPool (int numWorkers);
   }

And the app framework would call await Threading.CreatePThreadWebWorkerPool(numWorkers: AppConfig.RequestedPoolSize) at an appropriate time once the UI has been rendered.

We could also consider Task<bool> TryAddWebWorker() API for growing the worker pool.

The constraints from the runtime/Emsciprten/the web platform:

  • only callable on the main thread (although we could proxy the call over to the main thread in the runtime).
  • is async (we need to return to the JS event loop to send some messages back and forth to the fresh worker)
  • may fail if we hit the browser's limit on the number of workers per page
@lambdageek lambdageek added arch-wasm WebAssembly architecture area-VM-threading-mono labels Sep 14, 2022
@lambdageek lambdageek added this to the 8.0.0 milestone Sep 14, 2022
@ghost
Copy link

ghost commented Sep 14, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

By default we start the web worker pool that will host pthreads at app startup and wait for each worker to finish loading.
Compared to single threaded apps, this increased page load times.

Starting the worker pool at startup was reasonable because we just used Emscripten's worker startup code. But eventually we ended up overriding that startup sequence with our own code so that we could set up resources on the workers, transfer the MonoConfig, etc.

The upshot is that since we control the worker creation now, we don't have to do it when Emscripten used to. We can give app frameworks more control.

For example, we can provide a mechanism for the application (or the app framework) to start up the threadpool at a later time once the initial page is done loading. We could have an API like:

   namespace System.Runtime.InteropServices.JavaScript;

   public class Threading {
      // returns number of workers that were actually started
      public static Task<int> CreatePThreadWebWorkerPool (int numWorkers);
   }

And the app framework would call await Threading.CreatePThreadWebWorkerPool(numWorkers: AppConfig.RequestedPoolSize) at an appropriate time once the UI has been rendered.

We could also consider Task<bool> TryAddWebWorker() API for growing the worker pool.

The constraints from the runtime/Emsciprten/the web platform:

  • only callable on the main thread (although we could proxy the call over to the main thread in the runtime).
  • is async (we need to return to the JS event loop to send some messages back and forth to the fresh worker)
  • may fail if we hit the browser's limit on the number of workers per page
Author: lambdageek
Assignees: -
Labels:

arch-wasm, area-Threading-mono

Milestone: 8.0.0

@pavelsavara pavelsavara self-assigned this Jun 7, 2023
@pavelsavara pavelsavara modified the milestones: 8.0.0, 9.0.0 Jul 12, 2023
@pavelsavara pavelsavara added the os-browser Browser variant of arch-wasm label Nov 9, 2023
@pavelsavara pavelsavara changed the title [wasm-mt] Provide a way to start the web workers later [browser][mt] Provide a way to start the web workers later Nov 9, 2023
@pavelsavara pavelsavara changed the title [browser][mt] Provide a way to start the web workers later [browser][mt] Provide API to start the web workers later Jan 21, 2024
@pavelsavara
Copy link
Member

with deputy design this is no longer issue. We use all normal C# APIs to create threads

@github-actions github-actions bot locked and limited conversation to collaborators Apr 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-VM-threading-mono os-browser Browser variant of arch-wasm
Projects
Status: Done
Development

No branches or pull requests

2 participants