Skip to content

[browser][CoreCLR] lazy and satelite assemblies#124853

Open
pavelsavara wants to merge 7 commits intodotnet:mainfrom
pavelsavara:browser_lazy_assemblies
Open

[browser][CoreCLR] lazy and satelite assemblies#124853
pavelsavara wants to merge 7 commits intodotnet:mainfrom
pavelsavara:browser_lazy_assemblies

Conversation

@pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Feb 25, 2026

Contributes to #120226

@pavelsavara pavelsavara added this to the 11.0.0 milestone Feb 25, 2026
@pavelsavara pavelsavara self-assigned this Feb 25, 2026
@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label Feb 25, 2026
Copilot AI review requested due to automatic review settings February 25, 2026 12:04
@pavelsavara pavelsavara added area-Host os-browser Browser variant of arch-wasm labels Feb 25, 2026
@pavelsavara pavelsavara marked this pull request as ready for review February 25, 2026 12:05
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @jeffschwMSFT, @elinor-fung
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements support for loading satellite assemblies (localization resources) and lazy-loaded assemblies in the browser/CoreCLR JavaScript loader by wiring new loader export functions end-to-end (loader → cross-module table → interop INTERNAL.* APIs).

Changes:

  • Implemented loadSatelliteAssemblies / loadLazyAssembly by delegating to loader-side asset fetchers.
  • Added new loader exports (fetchSatelliteAssemblies, fetchLazyAssembly) to the cross-module exchange table and exposed them via dotnetLoaderExports.
  • Added support code for downloading/registration of satellite resources and lazy assemblies, plus PDB registration in the host FS.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/lazy.ts Implements interop entrypoints by delegating to loader exports.
src/native/libs/Common/JavaScript/types/exchange.ts Extends LoaderExports / LoaderExportsTable with new asset-fetching APIs.
src/native/libs/Common/JavaScript/loader/run.ts Optionally preloads all satellite resources during startup.
src/native/libs/Common/JavaScript/loader/index.ts Publishes the new loader functions into the cross-module table.
src/native/libs/Common/JavaScript/loader/config.ts Updates resource merging to include satellite resource keys (but currently duplicates data).
src/native/libs/Common/JavaScript/loader/assets.ts Adds fetchSatelliteAssemblies/fetchLazyAssembly and culture-aware assembly fetching.
src/native/libs/Common/JavaScript/host/assets.ts Updates assembly name aliasing and implements PDB registration into the VFS.
src/native/libs/Common/JavaScript/cross-module/index.ts Extends loader exports reconstruction from the exchange table.

Comment on lines 181 to 224
export async function fetchLazyAssembly(assemblyNameToLoad: string): Promise<boolean> {
const lazyAssemblies = loaderConfig.resources?.lazyAssembly;
if (!lazyAssemblies) {
throw new Error("No assemblies have been marked as lazy-loadable. Use the 'BlazorWebAssemblyLazyLoad' item group in your project file to enable lazy loading an assembly.");
}

let assemblyNameWithoutExtension = assemblyNameToLoad;
if (assemblyNameToLoad.endsWith(".dll"))
assemblyNameWithoutExtension = assemblyNameToLoad.substring(0, assemblyNameToLoad.length - 4);
else if (assemblyNameToLoad.endsWith(".wasm"))
assemblyNameWithoutExtension = assemblyNameToLoad.substring(0, assemblyNameToLoad.length - 5);

const assemblyNameToLoadDll = assemblyNameWithoutExtension + ".dll";
const assemblyNameToLoadWasm = assemblyNameWithoutExtension + ".wasm";

let dllAsset: AssemblyAsset | null = null;
for (const asset of lazyAssemblies) {
if (asset.virtualPath === assemblyNameToLoadDll || asset.virtualPath === assemblyNameToLoadWasm) {
dllAsset = asset;
break;
}
}

if (!dllAsset) {
throw new Error(`${assemblyNameToLoad} must be marked with 'BlazorWebAssemblyLazyLoad' item group in your project file to allow lazy-loading.`);
}

await fetchDll(dllAsset);

if (loaderConfig.debugLevel != 0) {
const pdbNameToLoad = assemblyNameWithoutExtension + ".pdb";
const pdbAssets = loaderConfig.resources?.pdb;
if (pdbAssets) {
for (const pdbAsset of pdbAssets) {
if (pdbAsset.virtualPath === pdbNameToLoad) {
await fetchPdb(pdbAsset);
break;
}
}
}
}

return true;
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetchLazyAssembly always returns true and re-registers the assembly even if it was already loaded previously. The existing WASM loader API returns false when the assembly is already loaded (see src/mono/browser/runtime/lazyLoading.ts) and avoids redundant downloads/allocations; the current behavior can leak memory because registerDllBytes allocates unmanaged memory each time. Track loaded assemblies (e.g., by asset name) and return false when already loaded.

Copilot uses AI. Check for mistakes.
Copy link
Member

@ilonatommy ilonatommy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from automated review (lazy loading / unexpected result of multiple calls of fetchDll) it loos good to me.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 25, 2026 14:50
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 25, 2026 15:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Host os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants