You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;publicclassThreading{// returns number of workers that were actually startedpublicstaticTask<int>CreatePThreadWebWorkerPool(intnumWorkers);}
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
The text was updated successfully, but these errors were encountered:
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;publicclassThreading{// returns number of workers that were actually startedpublicstaticTask<int>CreatePThreadWebWorkerPool(intnumWorkers);}
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
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
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
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:
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:
The text was updated successfully, but these errors were encountered: