@@ -35,6 +35,7 @@ export function mono_log_error(msg: string, ...data: any) {
3535}
3636
3737export const wasm_func_map = new Map < number , string > ( ) ;
38+ const wasm_pending_symbol_tables = new Array < string > ( ) ;
3839const regexes : any [ ] = [ ] ;
3940
4041// V8
@@ -54,6 +55,8 @@ regexes.push(/(?<replaceSection><[^ >]+>[.:]wasm-function\[(?<funcNum>[0-9]+)\])
5455
5556export 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
145148export 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
158175export function mono_wasm_get_func_id_to_name_mappings ( ) {
176+ performDeferredSymbolMapParsing ( ) ;
159177 return [ ...wasm_func_map . values ( ) ] ;
160178}
161179
162180export function mono_wasm_console_clear ( ) {
163181 console . clear ( ) ;
164- }
182+ }
0 commit comments