Enabling stack maps and GC safepoints adds another pass over the IR (emit_stackmaps) regardless whether the function in question actually uses reference types at all. One could imagine (especially with wasm-bindgen's "switch reference types into table indices at the boundaries" approach, that seems likely to be copied by C/C++) that many functions in a module don't use reference types. For these functions, that extra pass over the IR is a waste of time.
We could have a flag on functions that gets set if it uses reference types in any way (and then never gets unset when a particular reference type-using instruction is removed, so we don't have to precisely count them) and in emit_stackmaps, only walk the IR if the flag is set (and probably debug_assert! that it doesn't have any uses of reference types if the flag is not set).
This came up in #1832 (comment) for Wasmtime.
Enabling stack maps and GC safepoints adds another pass over the IR (
emit_stackmaps) regardless whether the function in question actually uses reference types at all. One could imagine (especially with wasm-bindgen's "switch reference types into table indices at the boundaries" approach, that seems likely to be copied by C/C++) that many functions in a module don't use reference types. For these functions, that extra pass over the IR is a waste of time.We could have a flag on functions that gets set if it uses reference types in any way (and then never gets unset when a particular reference type-using instruction is removed, so we don't have to precisely count them) and in
emit_stackmaps, only walk the IR if the flag is set (and probablydebug_assert!that it doesn't have any uses of reference types if the flag is not set).This came up in #1832 (comment) for Wasmtime.