Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser] wasm memory snapshot into browser cache #82049

Merged
merged 56 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
ea02d94
wip
pavelsavara Mar 3, 2023
c1aa6c3
wip
pavelsavara Mar 3, 2023
bf9ef4d
wip
pavelsavara Mar 3, 2023
f883a72
Merge branch 'main' into browser_memory_snapshot3
pavelsavara Mar 3, 2023
3fe9aba
wip
pavelsavara Mar 3, 2023
f4225aa
Merge branch 'main' into browser_memory_snapshot3
pavelsavara Mar 3, 2023
d2e5b49
fix
pavelsavara Mar 3, 2023
c409f51
Merge branch 'main' into browser_memory_snapshot3
pavelsavara Mar 6, 2023
e695c42
feedback
pavelsavara Mar 6, 2023
1189015
lint
pavelsavara Mar 6, 2023
b92c82e
Update src/mono/wasm/memory-snapshot.md
pavelsavara Mar 6, 2023
7ccc8e6
Update src/mono/wasm/memory-snapshot.md
pavelsavara Mar 6, 2023
ec762ac
Update src/mono/wasm/memory-snapshot.md
pavelsavara Mar 6, 2023
91c0211
Update src/mono/wasm/memory-snapshot.md
pavelsavara Mar 6, 2023
20d548b
Update src/mono/wasm/memory-snapshot.md
pavelsavara Mar 6, 2023
8e6865c
more linear memory usage and recovery from failure of snapshot use
pavelsavara Mar 6, 2023
7bf7881
feedback
pavelsavara Mar 6, 2023
aec9b53
Merge branch 'main' into browser_memory_snapshot3
pavelsavara Mar 8, 2023
5651f37
start runtime twice for unit tests, so that the actual tests is runni…
pavelsavara Mar 8, 2023
a16f667
Merge branch 'main' into browser_memory_snapshot3
pavelsavara Mar 8, 2023
31b46ff
wip
pavelsavara Mar 8, 2023
43a73e1
continue loading non-snapshot assets
pavelsavara Mar 8, 2023
f49354a
disable adding methods to __indirect_function_table before we take me…
pavelsavara Mar 8, 2023
53781ab
rename startupMemoryCache
pavelsavara Mar 8, 2023
60b2c5a
try to fix threads
pavelsavara Mar 8, 2023
33b6e3e
Merge branch 'main' into browser_memory_snapshot3
pavelsavara Mar 8, 2023
977b46c
whitespace
pavelsavara Mar 8, 2023
933594b
fix
pavelsavara Mar 9, 2023
c68c9e8
fix storing memory
pavelsavara Mar 9, 2023
fa3e331
assert
pavelsavara Mar 9, 2023
c7f913b
- make snapshot hash more resilient
pavelsavara Mar 9, 2023
9cb1b72
fix
pavelsavara Mar 9, 2023
d1bbb9c
- renamed memorySnapshotSkippedOrDone
pavelsavara Mar 9, 2023
ee4ba76
- rename loadedMemorySnapshot
pavelsavara Mar 9, 2023
83f0032
Merge branch 'main' into browser_memory_snapshot3
pavelsavara Mar 9, 2023
85ac81d
fix
pavelsavara Mar 9, 2023
b7790f2
Merge branch 'main' into browser_memory_snapshot3
pavelsavara Mar 10, 2023
3168c42
- internal config exitAfterSnapshot
pavelsavara Mar 10, 2023
4a25447
measure
pavelsavara Mar 10, 2023
5067cf7
Merge branch 'main' into browser_memory_snapshot3
pavelsavara Mar 11, 2023
1761786
fix
pavelsavara Mar 11, 2023
94e931a
fix
pavelsavara Mar 13, 2023
2a7508e
optimize timezone detection
pavelsavara Mar 13, 2023
9759ad8
feedback
pavelsavara Mar 13, 2023
1f4e4c6
fix
pavelsavara Mar 13, 2023
e2a2cd4
- enable snapshot in blazor
pavelsavara Mar 13, 2023
eaaeaa5
store cache key
pavelsavara Mar 13, 2023
bc86ffe
feedback and cleanup
pavelsavara Mar 13, 2023
59a7a56
fix debugging
pavelsavara Mar 13, 2023
6d9f7ee
fix
pavelsavara Mar 14, 2023
3e961d1
Merge branch 'main' into browser_memory_snapshot3
pavelsavara Mar 14, 2023
f617787
Update src/mono/wasm/memory-snapshot.md
pavelsavara Mar 14, 2023
cfc5acf
Update src/mono/wasm/memory-snapshot.md
pavelsavara Mar 14, 2023
c78ef57
Update src/mono/wasm/runtime/assets.ts
pavelsavara Mar 14, 2023
7309e43
Update src/mono/wasm/runtime/assets.ts
pavelsavara Mar 14, 2023
5f8aeef
Merge branch 'main' into browser_memory_snapshot3
pavelsavara Mar 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/mono/mono/mini/interp/jiterpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,9 @@ mono_jiterp_update_jit_call_dispatcher (WasmDoJitCall dispatcher)
// blocked the use of Module.addFunction
if (!dispatcher)
dispatcher = (WasmDoJitCall)mono_llvm_cpp_catch_exception;
else if (((int)(void*)dispatcher)==-1)
dispatcher = mono_jiterp_do_jit_call_indirect;

jiterpreter_do_jit_call = dispatcher;
}

Expand Down
1 change: 1 addition & 0 deletions src/mono/sample/wasm/browser-advanced/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script type='module' src="./dotnet.js"></script>
<link rel="preload" href="./mono-config.json" as="fetch" crossorigin="anonymous">
<link rel="prefetch" href="./dotnet.wasm" as="fetch" crossorigin="anonymous">
<!-- users should consider if they optimize for the first load or subsequent load from memory snapshot -->
<link rel="prefetch" href="./icudt.dat" as="fetch" crossorigin="anonymous">
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
<link rel="prefetch" href="./managed/System.Private.CoreLib.webcil" as="fetch" crossorigin="anonymous">
</head>
Expand Down
1 change: 1 addition & 0 deletions src/mono/sample/wasm/browser-bench/appstart-frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script type='module' src="./dotnet.js"></script>
<link rel="preload" href="./mono-config.json" as="fetch" crossorigin="anonymous">
<link rel="prefetch" href="./dotnet.wasm" as="fetch" crossorigin="anonymous">
<!-- users should consider if they optimize for the first load or subsequent load from memory snapshot -->
<link rel="prefetch" href="./icudt.dat" as="fetch" crossorigin="anonymous">
<link rel="prefetch" href="./managed/System.Private.CoreLib.dll" as="fetch" crossorigin="anonymous">
</head>
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/build/WasmApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@
<PropertyGroup>
<_WasmAppIncludeThreadsWorker Condition="'$(WasmEnableThreads)' == 'true' or '$(WasmEnablePerfTracing)' == 'true'">true</_WasmAppIncludeThreadsWorker>
<!-- TODO: set this from some user-facing property? -1 means use the default baked into dotnet.js -->
<_WasmPThreadPoolSize Condition="'$(_WasmPThreadPoolSize)' == '' and ('$(WasmEnableThreads)' == 'true' or '$(WasmEnablePerfTracing)' == 'true')">-1</_WasmPThreadPoolSize>
<_WasmPThreadPoolSize Condition="'$(_WasmPThreadPoolSize)' == ''">-1</_WasmPThreadPoolSize>
</PropertyGroup>

<ItemGroup>
Expand Down
27 changes: 27 additions & 0 deletions src/mono/wasm/memory-snapshot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Memory snapshot of the Mono runtime #
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved

We take snapshot of WASM memory after first cold start at run time​.
We store it on the client side in the browser cache.
For subsequent runs with the same configuration and same assets, we use the snapshot .
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
instead of downloading everything again and doing the runtime startup again.
These subsequent starts are significantly faster.

### Implementation details

- the consistency of inputs (configuration and assets) with the snapshot is done by calculating SHA256 of the inputs.
- the DLLs and other downloaded assets each have SHA256 which is used to validate 'integrity' by the browser.
- the mono-config has field `assetsHash` which is summary SHA256 of all the assets.
- the configuration could be changed programmatically and so we calculate the hash at the runtime, just before taking snapshot.
- the snapshot is taken just after we initialize the Mono runtime.
- before cwraps are initialized (they would be initialized again on subsequent start).
- after loading all the DLLs into memory.
- after loading ICU and timezone data.
- after applying environment variables and other runtime options.
- before any worker threads initialization.
- before any JavaScript interop initialization.
- before any Managed code executes.
- therefore we do not expect to store any application state in the snapshot.

### How to opt out
You can turn this feature of by calling `withStartupMemoryCache (false)` on [dotnet API](https://github.com/dotnet/runtime/blob/main/src/mono/wasm/runtime/dotnet.d.ts).

59 changes: 56 additions & 3 deletions src/mono/wasm/runtime/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { mono_wasm_load_bytes_into_heap } from "./memory";
import { endMeasure, MeasuredBlock, startMeasure } from "./profiler";
import { createPromiseController, PromiseAndController } from "./promise-controller";
import { delay } from "./promise-utils";
import { abort_startup, beforeOnRuntimeInitialized } from "./startup";
import { abort_startup, beforeOnRuntimeInitialized, memorySnapshotSkippedOrDone } from "./startup";
import { AssetBehaviours, AssetEntry, AssetEntryInternal, LoadingResource, mono_assert, ResourceRequest } from "./types";
import { InstantiateWasmSuccessCallback, VoidPtr } from "./types/emscripten";

Expand Down Expand Up @@ -38,6 +38,19 @@ const skipBufferByAssetTypes: {
"dotnetwasm": true,
};

const containedInSnapshotByAssetTypes: {
[k: string]: boolean
} = {
"resource": true,
"assembly": true,
"pdb": true,
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
"heap": true,
"icu": true,
"js-module-threads": true,
"dotnetwasm": true,
};


// these assets are instantiated differently than the main flow
const skipInstantiateByAssetTypes: {
[k: string]: boolean
Expand All @@ -63,8 +76,10 @@ export async function mono_download_assets(): Promise<void> {
runtimeHelpers.maxParallelDownloads = runtimeHelpers.config.maxParallelDownloads || runtimeHelpers.maxParallelDownloads;
runtimeHelpers.enableDownloadRetry = runtimeHelpers.config.enableDownloadRetry || runtimeHelpers.enableDownloadRetry;
try {
const alwaysLoadedAssets: AssetEntryInternal[] = [];
const containedInSnapshotAssets: AssetEntryInternal[] = [];
const promises_of_assets: Promise<AssetEntryInternal>[] = [];
// start fetching and instantiating all assets in parallel

for (const a of runtimeHelpers.config.assets!) {
const asset: AssetEntryInternal = a;
mono_assert(typeof asset === "object", "asset must be object");
Expand All @@ -73,14 +88,51 @@ export async function mono_download_assets(): Promise<void> {
mono_assert(!asset.resolvedUrl || typeof asset.resolvedUrl === "string", "asset resolvedUrl could be string");
mono_assert(!asset.hash || typeof asset.hash === "string", "asset resolvedUrl could be string");
mono_assert(!asset.pendingDownload || typeof asset.pendingDownload === "object", "asset pendingDownload could be object");
if (containedInSnapshotByAssetTypes[asset.behavior]) {
containedInSnapshotAssets.push(asset);
} else {
alwaysLoadedAssets.push(asset);
}
}

const countAndStartDownload = (asset: AssetEntryInternal) => {
if (!skipInstantiateByAssetTypes[asset.behavior] && shouldLoadIcuAsset(asset)) {
expected_instantiated_assets_count++;
}
if (!skipDownloadsByAssetTypes[asset.behavior] && shouldLoadIcuAsset(asset)) {
expected_downloaded_assets_count++;
promises_of_assets.push(start_asset_download(asset));
}
};

// start fetching and assets in parallel, only assets which are not part of memory snapshot
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
for (const asset of alwaysLoadedAssets) {
countAndStartDownload(asset);
}

// continue after we know if memory snapshot is available or not
await memorySnapshotSkippedOrDone.promise;

// start fetching and assets in parallel, only if memory snapshot is not available.
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
for (const asset of containedInSnapshotAssets) {
if (!runtimeHelpers.loadedMemorySnapshot) {
countAndStartDownload(asset);
} else {
// Otherwise cleanup in case we were given pending download. It would be even better if we could abort the download.
asset.pendingDownloadInternal = null as any; // GC
asset.pendingDownload = null as any; // GC
asset.buffer = null as any; // GC
// tell the debugger it is loaded
if (asset.behavior == "resource" || asset.behavior == "assembly" || asset.behavior == "pdb") {
const url = resolve_path(asset, "");
const virtualName: string = typeof (asset.virtualPath) === "string"
? asset.virtualPath
: asset.name;
loaded_files.push({ url: url, file: virtualName });
}
}
}

allDownloadsQueued.promise_control.resolve();

const promises_of_asset_instantiation: Promise<void>[] = [];
Expand All @@ -96,8 +148,9 @@ export async function mono_download_assets(): Promise<void> {
asset.pendingDownload = null as any; // GC
asset.buffer = null as any; // GC

// wait till after onRuntimeInitialized and after memory snapshot is loaded or skipped
await memorySnapshotSkippedOrDone.promise;
await beforeOnRuntimeInitialized.promise;
// this is after onRuntimeInitialized
_instantiate_asset(asset, url, data);
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/runtime/diagnostics/server_pthread/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class DiagnosticServerImpl implements DiagnosticServer {
}

async stopEventPipe(ws: WebSocket | MockRemoteSocket, sessionID: EventPipeSessionIDImpl): Promise<void> {
console.info("MONO_WASM: stopEventPipe", sessionID);
console.debug("MONO_WASM: stopEventPipe", sessionID);
cwraps.mono_wasm_event_pipe_session_disable(sessionID);
// we might send OK before the session is actually stopped since the websocket is async
// but the client end should be robust to that.
Expand Down Expand Up @@ -266,7 +266,7 @@ class DiagnosticServerImpl implements DiagnosticServer {

resumeRuntime(): void {
if (!this.runtimeResumed) {
console.info("MONO_WASM: resuming runtime startup");
console.debug("MONO_WASM: resuming runtime startup");
cwraps.mono_wasm_diagnostic_server_post_resume_runtime();
this.runtimeResumed = true;
}
Expand Down
6 changes: 6 additions & 0 deletions src/mono/wasm/runtime/dotnet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface DotnetHostBuilder {
withDebugging(level: number): DotnetHostBuilder;
withMainAssembly(mainAssemblyName: string): DotnetHostBuilder;
withApplicationArgumentsFromQuery(): DotnetHostBuilder;
withStartupMemoryCache(value: boolean): DotnetHostBuilder;
create(): Promise<RuntimeAPI>;
run(): Promise<number>;
}
Expand All @@ -38,6 +39,7 @@ declare interface EmscriptenModule {
HEAP8: Int8Array;
HEAP16: Int16Array;
HEAP32: Int32Array;
HEAP64: BigInt64Array;
HEAPU8: Uint8Array;
HEAPU16: Uint16Array;
HEAPU32: Uint32Array;
Expand Down Expand Up @@ -128,6 +130,10 @@ type MonoConfig = {
* initial number of workers to add to the emscripten pthread pool
*/
pthreadPoolSize?: number;
/**
* If true, the snapshot of runtime's memory will be stored in the browser and used for faster startup next time. Default is true.
*/
startupMemoryCache?: boolean;
/**
* hash of assets
*/
Expand Down
59 changes: 28 additions & 31 deletions src/mono/wasm/runtime/icu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,50 @@ import cwraps from "./cwraps";
import { Module, runtimeHelpers } from "./imports";
import { VoidPtr } from "./types/emscripten";

let num_icu_assets_loaded_successfully = 0;

// @offset must be the address of an ICU data archive in the native heap.
// returns true on success.
export function mono_wasm_load_icu_data(offset: VoidPtr): boolean {
const ok = (cwraps.mono_wasm_load_icu_data(offset)) === 1;
if (ok)
num_icu_assets_loaded_successfully++;
return ok;
return (cwraps.mono_wasm_load_icu_data(offset)) === 1;
}

// Performs setup for globalization.
// @globalizationMode is one of "icu", "invariant", or "auto".
// "auto" will use "icu" if any ICU data archives have been loaded,
// otherwise "invariant".
export function mono_wasm_globalization_init(): void {
const config = runtimeHelpers.config;
let invariantMode = false;
if (!config.globalizationMode)
config.globalizationMode = "auto";
if (config.globalizationMode === "invariant")
invariantMode = true;
export function init_globalization() {
runtimeHelpers.invariantMode = runtimeHelpers.config.globalizationMode === "invariant";
runtimeHelpers.preferredIcuAsset = get_preferred_icu_asset();

if (!invariantMode) {
if (num_icu_assets_loaded_successfully > 0) {
if (runtimeHelpers.diagnosticTracing) {
console.debug("MONO_WASM: ICU data archive(s) loaded, disabling invariant mode");
}
} else if (config.globalizationMode !== "icu") {
if (runtimeHelpers.diagnosticTracing) {
console.debug("MONO_WASM: ICU data archive(s) not loaded, using invariant globalization mode");
}
invariantMode = true;
if (!runtimeHelpers.invariantMode) {
if (runtimeHelpers.preferredIcuAsset) {
if (runtimeHelpers.diagnosticTracing) console.debug("MONO_WASM: ICU data archive(s) available, disabling invariant mode");
} else if (runtimeHelpers.config.globalizationMode !== "icu") {
if (runtimeHelpers.diagnosticTracing) console.debug("MONO_WASM: ICU data archive(s) not available, using invariant globalization mode");
runtimeHelpers.invariantMode = true;
runtimeHelpers.preferredIcuAsset = null;
} else {
const msg = "invariant globalization mode is inactive and no ICU data archives were loaded";
const msg = "invariant globalization mode is inactive and no ICU data archives are available";
Module.err(`MONO_WASM: ERROR: ${msg}`);
throw new Error(msg);
}
}

if (invariantMode) {
cwraps.mono_wasm_setenv("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1");
const invariantEnv = "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT";
const env_variables = runtimeHelpers.config.environmentVariables!;
if (env_variables[invariantEnv] === undefined && runtimeHelpers.invariantMode) {
env_variables[invariantEnv] = "1";
}
if (env_variables["TZ"] === undefined) {
try {
// this call is relatively expensive, so we call it during download of other assets
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || null;
if (timezone) {
env_variables!["TZ"] = timezone;
}
} catch {
console.info("MONO_WASM: failed to detect timezone, will fallback to UTC");
}
}
}

export function get_preferred_icu_asset(): string | null {
if (!runtimeHelpers.config.assets)
if (!runtimeHelpers.config.assets || runtimeHelpers.invariantMode)
return null;

// By setting <WasmIcuDataFileName> user can define what ICU source file they want to load.
Expand Down
3 changes: 2 additions & 1 deletion src/mono/wasm/runtime/jiterpreter-jit-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { mono_assert, MonoType, MonoMethod } from "./types";
import { NativePointer, Int32Ptr, VoidPtr } from "./types/emscripten";
import { Module } from "./imports";
import { Module, runtimeHelpers } from "./imports";
import {
getU8, getI32_unaligned, getU32_unaligned, setU32_unchecked
} from "./memory";
Expand Down Expand Up @@ -256,6 +256,7 @@ function getIsWasmEhSupported () : boolean {
export function mono_jiterp_do_jit_call_indirect (
jit_call_cb: number, cb_data: VoidPtr, thrown: Int32Ptr
) : void {
mono_assert(!runtimeHelpers.storeMemorySnapshotPending, "Attempting to set function into table during creation of memory snapshot");
const table = getWasmFunctionTable();
const jitCallCb = table.get(jit_call_cb);

Expand Down
7 changes: 4 additions & 3 deletions src/mono/wasm/runtime/jiterpreter-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { mono_assert } from "./types";
import { NativePointer, ManagedPointer, VoidPtr } from "./types/emscripten";
import { Module } from "./imports";
import { Module, runtimeHelpers } from "./imports";
import { WasmOpcode } from "./jiterpreter-opcodes";
import cwraps from "./cwraps";

Expand Down Expand Up @@ -1201,8 +1201,9 @@ export function getWasmFunctionTable () {
}

export function addWasmFunctionPointer (f: Function) {
if (!f)
throw new Error("Attempting to set null function into table");
mono_assert(f,"Attempting to set null function into table");
mono_assert(!runtimeHelpers.storeMemorySnapshotPending, "Attempting to set function into table during creation of memory snapshot");

const table = getWasmFunctionTable();
if (wasmFunctionIndicesFree <= 0) {
wasmNextFunctionIndex = table.length;
Expand Down
4 changes: 3 additions & 1 deletion src/mono/wasm/runtime/jiterpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { mono_assert, MonoMethod } from "./types";
import { NativePointer } from "./types/emscripten";
import { Module } from "./imports";
import { Module, runtimeHelpers } from "./imports";
import {
getU16, getU32_unaligned
} from "./memory";
Expand Down Expand Up @@ -762,6 +762,8 @@ function generate_wasm (
// independently jitting traces will not stomp on each other and all threads
// have a globally consistent view of which function pointer maps to each trace.
rejected = false;
mono_assert(!runtimeHelpers.storeMemorySnapshotPending, "Attempting to set function into table during creation of memory snapshot");

const idx =
trapTraceErrors
? Module.addFunction(
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/runtime/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export async function init_polyfills_async(): Promise<void> {
}
}
}
runtimeHelpers.subtle = globalThis.crypto?.subtle;
}

const dummyPerformance = {
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/runtime/profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const enum MeasuredBlock {
preRunWorker = "mono.preRunWorker",
onRuntimeInitialized = "mono.onRuntimeInitialized",
postRun = "mono.postRun",
memorySnapshot = "mono.memorySnapshot",
loadRuntime = "mono.loadRuntime",
bindingsInit = "mono.bindingsInit",
bindJsFunction = "mono.bindJsFunction:",
Expand Down
14 changes: 14 additions & 0 deletions src/mono/wasm/runtime/run-outer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface DotnetHostBuilder {
withDebugging(level: number): DotnetHostBuilder
withMainAssembly(mainAssemblyName: string): DotnetHostBuilder
withApplicationArgumentsFromQuery(): DotnetHostBuilder
withStartupMemoryCache(value: boolean): DotnetHostBuilder
create(): Promise<RuntimeAPI>
run(): Promise<number>
}
Expand Down Expand Up @@ -137,6 +138,19 @@ class HostBuilder implements DotnetHostBuilder {
}
}

withStartupMemoryCache(value: boolean): DotnetHostBuilder {
try {
const configInternal: MonoConfigInternal = {
startupMemoryCache: value
};
Object.assign(this.moduleConfig.config!, configInternal);
return this;
} catch (err) {
mono_exit(1, err);
throw err;
}
}

withConfig(config: MonoConfig): DotnetHostBuilder {
try {
const providedConfig = { ...config };
Expand Down
Loading