Skip to content

Commit ef8780b

Browse files
committed
Defer parsing of wasm stack symbolication maps until point of first use instead of during startup
1 parent b9dfd37 commit ef8780b

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

src/mono/browser/runtime/dotnet.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//!
44
//! This is generated file, see src/mono/wasm/runtime/rollup.config.js
55

6-
//! This is not considered public API with backward compatibility guarantees.
6+
//! This is not considered public API with backward compatibility guarantees.
77

88
declare interface NativePointer {
99
__brandNativePointer: "NativePointer";
@@ -336,7 +336,7 @@ interface AssetEntry {
336336
*/
337337
pendingDownload?: LoadingResource;
338338
}
339-
type SingleAssetBehaviors =
339+
type SingleAssetBehaviors =
340340
/**
341341
* The binary of the .NET runtime.
342342
*/
@@ -362,14 +362,14 @@ type SingleAssetBehaviors =
362362
*/
363363
| "manifest"
364364
/**
365-
* The debugging symbols
365+
* The debugging symbols used to demangle wasm stack traces; from 'wasm:0x123456' to a C function name
366366
*/
367367
| "symbols"
368368
/**
369369
* Load segmentation rules file for Hybrid Globalization.
370370
*/
371371
| "segmentation-rules";
372-
type AssetBehaviors = SingleAssetBehaviors |
372+
type AssetBehaviors = SingleAssetBehaviors |
373373
/**
374374
* Load asset as a managed resource assembly.
375375
*/

src/mono/browser/runtime/logging.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function mono_log_error(msg: string, ...data: any) {
3535
}
3636

3737
export const wasm_func_map = new Map<number, string>();
38+
const wasm_pending_symbol_tables = new Array<string>();
3839
const regexes: any[] = [];
3940

4041
// V8
@@ -54,6 +55,8 @@ regexes.push(/(?<replaceSection><[^ >]+>[.:]wasm-function\[(?<funcNum>[0-9]+)\])
5455

5556
export function mono_wasm_symbolicate_string(message: string): string {
5657
try {
58+
performDeferredSymbolMapParsing();
59+
5760
if (wasm_func_map.size == 0)
5861
return message;
5962

@@ -143,22 +146,37 @@ export function mono_wasm_trace_logger(log_domain_ptr: CharPtr, log_level_ptr: C
143146

144147

145148
export function parseSymbolMapFile(text: string) {
146-
text.split(/[\r\n]/).forEach((line: string) => {
147-
const parts: string[] = line.split(/:/);
148-
if (parts.length < 2)
149-
return;
150-
151-
parts[1] = parts.splice(1).join(":");
152-
wasm_func_map.set(Number(parts[0]), parts[1]);
153-
});
149+
// Symbol map parsing is very expensive, so doing it during startup is wasteful
150+
// instead, we defer it until the first time the symbol map is needed - which
151+
// may be never
152+
wasm_pending_symbol_tables.push(text);
153+
mono_log_debug(`Deferred loading of ${text.length}ch symbol map`);
154+
}
154155

155-
mono_log_debug(`Loaded ${wasm_func_map.size} symbols`);
156+
function performDeferredSymbolMapParsing() {
157+
while (wasm_pending_symbol_tables.length > 0) {
158+
const text = wasm_pending_symbol_tables.shift()!;
159+
try {
160+
text.split(/[\r\n]/).forEach((line: string) => {
161+
const parts: string[] = line.split(/:/);
162+
if (parts.length < 2)
163+
return;
164+
165+
parts[1] = parts.splice(1).join(":");
166+
wasm_func_map.set(Number(parts[0]), parts[1]);
167+
});
168+
mono_log_debug(`Loaded ${wasm_func_map.size} symbols`);
169+
} catch (exc) {
170+
mono_log_warn(`Failed to load symbol map: ${exc}`);
171+
}
172+
}
156173
}
157174

158175
export function mono_wasm_get_func_id_to_name_mappings() {
176+
performDeferredSymbolMapParsing();
159177
return [...wasm_func_map.values()];
160178
}
161179

162180
export function mono_wasm_console_clear() {
163181
console.clear();
164-
}
182+
}

0 commit comments

Comments
 (0)