Repository navigation
feat: Implement VFS Framework Assembly Loading and cleanup support - #1050
Conversation
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://white-river-0087b630f-1050.eastus2.1.azurestaticapps.net |
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://white-river-0087b630f-1050.eastus2.1.azurestaticapps.net |
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://white-river-0087b630f-1050.eastus2.1.azurestaticapps.net |
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://white-river-0087b630f-1050.eastus2.1.azurestaticapps.net |
There was a problem hiding this comment.
Pull request overview
Adds an opt-in WebAssembly bootstrap feature to place (non-entrypoint) assemblies into Emscripten VFS to leverage Mono’s filename-based image cache across AssemblyLoadContexts, with an optional cleanup hook to unlink VFS files after load, plus CI/runtime validation and docs.
Changes:
- Introduce MSBuild properties and config surface (
uno_vfs_framework_assembly_load,uno_vfs_framework_assembly_load_cleanup) to enable VFS-based assembly loading and optional cleanup. - Update the WASM bootstrapper to redirect resource groups to
resources.vfs["/managed"], setMONO_PATH, and optionally delete/managed/*files on close. - Add a new Puppeteer-based runtime test (and CI step) validating VFS loading + cleanup, and document the feature.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/Bootstrapper.ts | Implements VFS redirection, MONO_PATH setting, and optional VFS cleanup hook. |
| src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/UnoConfig.ts | Adds config flags for enabling VFS loading/cleanup. |
| src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets | Defines MSBuild properties and passes them into the Shell task. |
| src/Uno.Wasm.Bootstrap/ShellTask.cs | Emits new config flags into uno-config.js. |
| src/Uno.Wasm.Sample.RayTracer/Uno.Wasm.Sample.RayTracer.csproj | Enables VFS assembly load in the sample project. |
| src/Uno.Wasm.Tests.VfsAssemblyLoad/test-vfs-assembly-load.sh | Publishes RayTracer with VFS flags and runs runtime validation. |
| src/Uno.Wasm.Tests.VfsAssemblyLoad/validate-vfs-runtime.js | Puppeteer validation for successful run, config flags, and VFS cleanup behavior. |
| src/Uno.Wasm.Tests.VfsAssemblyLoad/package.json | Adds Puppeteer dependency for the new validation script. |
| build/ci/stage-build-linux-tests.yml | Runs the new VFS assembly load test in CI and publishes artifacts. |
| doc/features-vfs-assembly-loading.md | Documents the feature, enablement, and cleanup behavior. |
| doc/toc.yml | Adds the new documentation page to the docs TOC. |
| Readme.md | Links to the new documentation page. |
Comments suppressed due to low confidence (5)
doc/features-vfs-assembly-loading.md:9
- The feature/property names say “Framework Assembly Loading”, but the described behavior (and the bootstrapper logic) applies to all assemblies in
config.resources.assemblyexcept the main assembly. Either adjust the wording to match the actual scope (e.g., “assembly loading”) or constrain the implementation/docs to framework assemblies only, to avoid misleading users.
# VFS Framework Assembly Loading
By default the .NET WebAssembly runtime loads assemblies as in-memory bundled resources via `mono_wasm_add_assembly`. Each `AssemblyLoadContext` (ALC) that loads the same assembly receives its own `MonoImage` copy, which can lead to significant memory duplication in applications that create multiple ALCs.
When VFS Framework Assembly Loading is enabled, assemblies are placed in the Emscripten virtual filesystem (VFS) instead of being registered as bundled resources. The Mono runtime's filename-based image cache (`mono_image_open_a_lot`) then deduplicates `MonoImage` instances across ALCs: the first load reads the file from the VFS, and subsequent loads of the same path return the cached image without allocating additional memory.
src/Uno.Wasm.Tests.VfsAssemblyLoad/validate-vfs-runtime.js:12
- The file header claims the script verifies “MONO_PATH was set to /managed in the runtime config”, but the script doesn’t actually assert the
MONO_PATHvalue (it only checks the Uno config feature flags and behavior). Either add an explicit check forMONO_PATH(if it’s observable) or update the header comment to match what’s being validated.
* 1. The app ran successfully (assemblies loaded from VFS via MONO_PATH).
* 2. MONO_PATH was set to /managed in the runtime config.
* 3. VFS cleanup removed assembly files from /managed after they were read.
*
src/Uno.Wasm.Bootstrap/ShellTask.cs:582
- This generated JS line is missing the trailing semicolon, while the rest of
uno-config.jsassignments consistently include one. Even though ASI likely makes it work, keeping the semicolon avoids style drift and reduces risk if additional code is appended later.
config.AppendLine($"config.uno_vfs_framework_assembly_load = {VfsFrameworkAssemblyLoad.ToString().ToLowerInvariant()};");
config.AppendLine($"config.uno_vfs_framework_assembly_load_cleanup = {VfsFrameworkAssemblyLoadCleanup.ToString().ToLowerInvariant()};");
config.AppendLine($"config.emcc_exported_runtime_methods = [{emccExportedRuntimeMethodsParams}]");
src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/Bootstrapper.ts:359
redirectAssembliesToVfsoverwrites any existingMONO_PATHset inconfig.environmentVariables(e.g., via@(WasmShellMonoEnvironment)or other tooling). This can unintentionally drop user-provided probe paths. Consider preserving the existing value and prepending/appending/managedonly when it’s not already present (using the runtime’s expected path separator).
// Set MONO_PATH so the runtime probes this directory for assemblies
config.environmentVariables = config.environmentVariables || {};
config.environmentVariables["MONO_PATH"] = vfsManagedDir;
doc/features-vfs-assembly-loading.md:49
- The markdown table under “MSBuild properties” has an extra leading
|on each row (e.g.|| Property ...). This won’t render as a proper table in most markdown renderers. Please format it as a standard table (| Property | Default | Description |, etc.).
| Property | Default | Description |
|---|---|---|
| `WasmShellVfsFrameworkAssemblyLoad` | `false` | Place framework assemblies in the Emscripten VFS instead of loading them as bundled resources. |
| `WasmShellVfsFrameworkAssemblyLoadCleanup` | `false` | Delete assembly files from the VFS after the runtime closes them. Requires `WasmShellVfsFrameworkAssemblyLoad`. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
No description provided.