Skip to content

Commit

Permalink
fix(threads): missing max threads parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Nov 9, 2022
1 parent 87a47e9 commit ee4fbec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/features-environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
4 changes: 3 additions & 1 deletion doc/features-threading.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,6 +26,8 @@ To change the number of threads available to the app, use the following:
</PropertyGroup>
```

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.

Expand Down
7 changes: 6 additions & 1 deletion src/Uno.Wasm.Bootstrap/ShellTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ee4fbec

Please sign in to comment.