Search code examples
c++webassemblyemscriptenfirefox-developer-tools

When executing WASM in Firefox, what is "debug trap handling"


I've compiled a large chunk of C++ code to WASM using enscriptem, and am trying to optimize its performance. Here is what my profiler is showing:

Total Time   Total Cost  Self Time   Self Cost   Samples Function
51,272.77 ms    94.46%  51,272.77 ms    94.46%  29273   debug trap handling (in wasm)   Gecko
4,434.89 ms 8.17%   0 ms    0%  0       std::__2::__compressed_pair_elem<std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >::__rep, 0, false>::__get() const   qalc.wasm   :3795283    localhost:8000
4,264.99 ms 7.86%   0 ms    0%  0       std::__2::__compressed_pair<std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >::__rep, std::__2::allocator<char> >::first() const  qalc.wasm   :3795198    localhost:8000
2,981.12 ms 5.49%   0 ms    0%  0       free  qalc.wasm   :3867464    localhost:8000

What does the "debug trap handling" section mean, and why is my code spending so much time in it?


Solution

  • I think that means Firefox compiled the Wasm such that it is suitable for debugging, so you can step through the Wasm line by line, since the profiler is open. This usually means that it is interpreted. (It does not have to do with the flags you use to compile you C++ project.)

    Not super sure if there's a way to profile from the command line, maybe you can try inserted calls to console.profile(); to surround parts of your C++ code that you care about.