FirefoxはDevToolsを開いているとWebAssemblyが遅くなる
追記
DevToolsを開いただけでは遅くならなくなったらしい!
https://bugzilla.mozilla.org/show_bug.cgi?id=1719615
実際に WASM をデバッグしようとしない限りは大丈夫?
Firefox 100~
TL;DR
DevToolsを開いていると WebAssembly のデバッグ機能を提供するために一番遅い Baseline JIT コンパイラが使われる
ので DevTools を開いていると WebAssembly の実行が遅くなる
Workaround
Baseline JIT コンパイラを無効化するとDevToolsを開いている時に使えるコンパイラがなくなる
のでエラーが出るようになり気づける
javascript.options.wasm_baselinejit を false に
FirefoxはDevToolsを開いているとWebAssemblyが遅くなる
本当?
2〜8倍くらい遅くなる (WebAssemblyにやらせる内容依存)
例: RGBA2222 から RGBA8888 (ImageData) に変換する処理
DevToolsを閉じている時
https://gyazo.com/445ea25a8a9a12b94f81f1a285457ef8
DevToolsを開いている時
https://gyazo.com/f3d102bd45c663b7539ef57e206a036b
(lower is better)
javascript.options.wasm_verbose を true にしてみると
devtoolsを開いている時は available wasm compilers: tier1=baseline tier2=none
devtoolsを閉じている時は available wasm compilers: tier1=baseline tier2=ion
このlogはどこから出ているのか?
https://searchfox.org/mozilla-central/search?q=available+wasm+compilers&case=true&path=
js/src/wasm/WasmCompile.cpp っぽい
code:cpp
Log(cx, "available wasm compilers: tier1=%s tier2=%s",
baseline ? "baseline" : "none",
ion ? "ion" : (cranelift ? "cranelift" : "none"));
tier1: baseline or none
tier2: ion or cranelift or none
tier2 compiler が devtools を開いていると使えない?
code:cpp
// Debug information such as source view or debug traps will require
// additional memory and permanently stay in baseline code, so we try to
// only enable it when a developer actually cares: when the debugger tab
// is open.
bool debug = cx->realm() && cx->realm()->debuggerObservesAsmJS();
DevToolsを開いていると debug 情報を提供するために baseline JIT が強制されるらしい
そんな〜〜
まあデバッグビルドは遅いというのはそれはそうなんだが、warningの1つくらい出しておいてほしい
出典
https://hg.mozilla.org/mozilla-central/file/7bc2dd06085f53993037b4fc78ee651c5afc7671/js/src/wasm/WasmCompile.cpp