Skip to content

Commit

Permalink
feat: Add 4GB memory configuration detection support
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Jan 18, 2022
1 parent 2462cb7 commit 3669e0c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Readme.md
Expand Up @@ -857,9 +857,22 @@ The bootstrapper provides a set of environment variables that reflect the config
- `UNO_BOOTSTRAP_MONO_PROFILED_AOT`, which specifies if the package was built using a PG-AOT profile.
- `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.
Those variables can be accessed through [Environment.GetEnvironmentVariable](https://docs.microsoft.com/en-us/dotnet/api/system.environment.getenvironmentvariable).
### 4GB memory support
The support for 4GB memory space is available by adding the following configuration:
```xml
<ItemGroup>
<WasmShellExtraEmccFlags Include="-s MAXIMUM_MEMORY=4GB"/>
</ItemGroup>
```
The configuration can also be detected at runtime using the `UNO_BOOTSTRAP_EMSCRIPTEN_MAXIMUM_MEMORY` environment variable, which will be set to `4GB` once set.
See this [blog post from the v8 team](https://v8.dev/blog/4gb-wasm-memory) for more information.
### Dependency management
The Uno Bootstrapper uses RequireJS for dependency management, allowing for dependencies to be resolved in a stable manner.
Expand Down
6 changes: 6 additions & 0 deletions src/Uno.Wasm.Bootstrap/ShellTask.cs
Expand Up @@ -1646,6 +1646,12 @@ private void GenerateConfig()
AddEnvironmentVariable("UNO_BOOTSTRAP_APP_BASE", _remoteBasePackagePath);
AddEnvironmentVariable("UNO_BOOTSTRAP_WEBAPP_BASE_PATH", WebAppBasePath);

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
AddEnvironmentVariable("UNO_BOOTSTRAP_EMSCRIPTEN_MAXIMUM_MEMORY", "4GB");
}

if (EnableLogProfiler)
{
AddEnvironmentVariable("UNO_BOOTSTRAP_LOG_PROFILER_OPTIONS", LogProfilerOptions);
Expand Down
Expand Up @@ -22,6 +22,10 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
<WasmShellExtraEmccFlags Include="-s MAXIMUM_MEMORY=4GB"/>
</ItemGroup>

<Import Project="..\Uno.Wasm.Sample\Uno.Wasm.Sample.projitems" Label="Shared" />

<Import Project="..\Uno.Wasm.Sample\sample.common.props" />
Expand Down

0 comments on commit 3669e0c

Please sign in to comment.