-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[wasm-mt] Publish dotnet.worker.js
#68509
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
dotnet.worker.js
dotnet.worker.js
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsThe There may also be an issue with Blazor
|
We probably need a way how to customize it.
|
@javiercn if we populate a msbuild item with the files to deploy (not exhaustive), then would you be able to use that to ensure that they get deployed wherever needed? |
It is worth reading through #48016 as well |
renaming tl;dr if we want the published app to use different/consistent naming for worker JS files, we can do that. |
We're going to need to install a replacement for allocateUnusedWorker: function() {
if (!Module["locateFile"]) {
PThread.unusedWorkers.push(new Worker(new URL("dotnet.worker.js", import.meta.url)));
return;
}
var pthreadMainJs = locateFile("dotnet.worker.js");
PThread.unusedWorkers.push(new Worker(pthreadMainJs));
}, We should use the new Note that emscripten pre-allocates at startup by calling PThread.init (); in its giant global initialization (before it calls the |
Replacing On the bright side So we could:
I'm going to give it a go |
The way how to resolve the asset is now merged
You will also need to add it to the mono-config.json via
|
This is what SDK needs to do https://github.com/dotnet/sdk/pull/26966/files |
yep, I have it basically working. PR soon |
…er (#73697) Enables using asset loading to get the `dotnet.worker.js` file that provides the emscripten pthread worker code. Also allows specifying the number of pre-allocated workers that will be created at startup using MSBuild properties. Fixes #68509 and fixes #68397 and fixes #72606 - Override Emscripten `PThread.allocateUnusedWorker` We want to use our own allocateUnusedWorker because we want to load `dotnet.worker.js` using our asset loading machinery. Unfortunately, Emscripten first calls allocateUnusedWorker very early (from `PThread.init`) to pre-allocate the pthread worker pool. So we set Emscripten's own pthread worker pool to size 0 and make our own. This requires calling `loadWasmModuleToWorker` during our startup because Emscripten deletes their code that normally does it (in "receiveInstance" in "createWasm" in "emscripten/src/preamble.js") when the pthread pool size is 0. Also added a pthreadPoolSize field to MonoConfig to allow specifying the initial pthread pool size in mono-config.json - Add `IncludeThreadsWorker` and `PThreadPoolSize` props to WasmAppBuilder `IncludeThreadsWorker` adds the `"js-module-threads"` asset to the `mono-config.json` `PThreadPoolSize` can be -1 or >=0 to specify the number of workers that will be pre-allocated at startup for the pthread worker pool. -1 means use the default compiled into `dotnet.js` - Reorganize the pthreads TS code by moving `Internals` (access API that digs through Emscripten's pthreads implementation) to its own module. And add types. - Replace emscripten's `allocateUnusedWorker` function with our own that goes through the asset loading API. - Update samples - Set up console proxying for the workers. This is done by sending a message from the main thread to the pthread workers with the current `MonoConfig` on our dedicated channel. (This means the proxying is setup asynchronously, so if the worker is busy before it receives the message, it may not start redirecting messages right away). --- * [wasm-mt] Override Emscripten PThread.allocateUnusedWorker We want to use our own allocateUnusedWorker because we want to load `dotnet.worker.js` using our asset loading machinery. Unfortunately, Emscripten first calls allocateUnusedWorker very early (from `PThread.init`) to pre-allocate the pthread worker pool. So we set Emscripten's own pthread worker pool to size 0 and make our own. This requires calling `loadWasmModuleToWorker` during our startup because Emscripten deletes their code that normally does it (in "receiveInstance" in "createWasm" in "emscripten/src/preamble.js") when the pthread pool size is 0. Also added a pthreadPoolSize field to MonoConfig to allow specifying the initial pthread pool size in mono-config.json * Add IncludeThreadsWorker and PThreadPoolSize props to WasmAppBuilder IncludeThreadsWorker adds the js-module-threads asset to the mono-config PThreadPoolSize can be -1 or >=0 to specify the number of workers that will be pre-allocated at startup for the pthread worker pool. -1 means use the default compiled into dotnet.js * Move emscripten PThread internals access to a separate module and add types * Load js-module-threads asset in replacement allocateUnusedWorker * Update samples to explicitly enable threading / perftracing Makes the WasmAppBuilder include the threads worker module * tighten up Internals types * apply review feedback * fix import * Apply suggestions from code review * proxy pthread worker messages to websocket, if enabled use a new MonoThreadMessageApplyMonoConfig message to send the MonoConfig from the main thread to each worker when the workers set up the communication channel to the main thread. then if the diagnosticTracing property is true, redirect the worker console logging to a websocket. Fixes #72606 Co-authored-by: Marek Fišera <[email protected]> Co-authored-by: Ankit Jain <[email protected]>
The
WasmApp.targets
should placedotnet.worker.js
next todotnet.js
There may also be an issue with Blazor
dotnet publish
doing likewise.The text was updated successfully, but these errors were encountered: