From ee4fbecac948ecbd131233718c466444cd33f925 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Tue, 8 Nov 2022 22:43:46 -0500 Subject: [PATCH] fix(threads): missing max threads parameter --- doc/features-environment-variables.md | 1 + doc/features-threading.md | 4 +++- src/Uno.Wasm.Bootstrap/ShellTask.cs | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/features-environment-variables.md b/doc/features-environment-variables.md index 21d6cf54c..b024bc71a 100644 --- a/doc/features-environment-variables.md +++ b/doc/features-environment-variables.md @@ -27,5 +27,6 @@ The bootstrapper provides a set of environment variables that reflect the config - `UNO_BOOTSTRAP_APP_BASE`, which specifies the location of the app content from the base. Useful to reach assets deployed using the `UnoDeploy="Package"` mode. - `UNO_BOOTSTRAP_WEBAPP_BASE_PATH`, which specifies the base location of the webapp. This parameter is used in the context of deep-linking (through the `WasmShellWebAppBasePath` property). This property must contain a trailing `/` and its default is `./`. - `UNO_BOOTSTRAP_EMSCRIPTEN_MAXIMUM_MEMORY`, which optionally specifies the maximum memory available to the WebAssembly module. +- `UNO_BOOTSTRAP_MAX_THREADS`, which provides the maximum number of threads that can be created. Those variables can be accessed through [Environment.GetEnvironmentVariable](https://docs.microsoft.com/en-us/dotnet/api/system.environment.getenvironmentvariable). diff --git a/doc/features-threading.md b/doc/features-threading.md index 58b3d0891..17b688141 100644 --- a/doc/features-threading.md +++ b/doc/features-threading.md @@ -17,7 +17,7 @@ Threading support can be detected at runtime by using the [`UNO_BOOTSTRAP_MONO_R ### Controlling the browser thread pool size -By default, the runtime pre-creates a set of 4 Web Workers available to WebAssembly threads, and the .NET Runtime will reuse the workers as threads stop. +By default, the runtime pre-creates a set of 4 WebWorkers available to WebAssembly threads, and the .NET Runtime will reuse the workers as threads stop. This value is used by the `ThreadPool` and `Tasks` subsystems. To change the number of threads available to the app, use the following: ```xml @@ -26,6 +26,8 @@ To change the number of threads available to the app, use the following: ``` +The maximum number of threads can be determined by the `UNO_BOOTSTRAP_MAX_THREADS` environment variable. + ### Restrictions WebAssembly Threads are using the `SharedArrayBuffer` browser feature, which is disabled in most cases for security reasons. diff --git a/src/Uno.Wasm.Bootstrap/ShellTask.cs b/src/Uno.Wasm.Bootstrap/ShellTask.cs index a3c489648..6d180c49f 100644 --- a/src/Uno.Wasm.Bootstrap/ShellTask.cs +++ b/src/Uno.Wasm.Bootstrap/ShellTask.cs @@ -772,7 +772,7 @@ private void RunPackager() var pthreadPoolSizeParam = $"--pthread-pool-size={PThreadsPoolSize}"; var enableICUParam = EnableNetCoreICU ? "--icu" : ""; - var monovmparams = $"--framework=net5 --runtimepack-dir=\"{AlignPath(MonoWasmSDKPath)}\" {enableICUParam} "; + var monovmparams = $"--framework=net5 --runtimepack-dir=\"{AlignPath(MonoWasmSDKPath)}\" {enableICUParam} {pthreadPoolSizeParam}"; var pass1ResponseContent = $"{runtimeConfigurationParam} {appDirParm} {monovmparams} --zlib {debugOption} {referencePathsParameter} \"{AlignPath(TryConvertLongPath(Path.GetFullPath(Assembly)))}\""; var packagerPass1ResponseFile = Path.Combine(workAotPath, "packager-pass1.rsp"); @@ -1866,6 +1866,11 @@ private void GenerateConfig() AddEnvironmentVariable("UNO_BOOTSTRAP_APP_BASE", _remoteBasePackagePath); AddEnvironmentVariable("UNO_BOOTSTRAP_WEBAPP_BASE_PATH", WebAppBasePath); + if (EnableThreads) + { + AddEnvironmentVariable("UNO_BOOTSTRAP_MAX_THREADS", PThreadsPoolSize.ToString()); + } + if (ExtraEmccFlags?.Any(f => f.ItemSpec?.Contains("MAXIMUM_MEMORY=4GB") ?? false) ?? false) { // Detects the use of the 4GB flag: https://v8.dev/blog/4gb-wasm-memory