Skip to content

Conversation

@quantum5
Copy link
Member

@quantum5 quantum5 commented Jun 10, 2019

Rationale

Running the sqlite3 test with the experimental LSan code in #8711 results in around 12x slowdown compared to no LSan. We can do better. The obvious suspect is the stack tracing code, since that is called every malloc, and on native, the sanitizers take special effort in making stack unwinding fast, even at the cost of accuracy.

This PR contains most of the easy changes, and with it, the LSan code results in around 4x slowdown, a 3x improvement compared to before.

Changes

  • directly unwind into a C buffer in one call instead of calling a JS helper in a loop
  • make emscripten_stack_snapshot return __builtin_return_address(0) since the value is readily available, saving the trouble of doing another stack trace
  • use new Error().stack instead of emscripten_get_callstack_js, avoiding parsing and reformatting stack trace just to parse it again
  • Look up the PC value in the source map directly (post-Add compatibility for source maps with v8's stack frame format #8762, it's always the module offset) instead of parsing the stack frame again
  • Cache the last result of emscripten_pc_get_source_js since emscripten_pc_get_* all call it, and typically with the same arguments

WASM library cache needs to be cleared after this change lands, since the old libsanitizer_common_rt_wasm.a depends on a function that is now removed.

@quantum5 quantum5 requested review from aheejin, kripken and tlively June 10, 2019 21:33
@quantum5 quantum5 requested a review from kripken June 12, 2019 21:19
@quantum5
Copy link
Member Author

The PR that this PR depended on, #8762, has been merged. The diff is now clean.

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. How much of a speedup is this?

@quantum5 quantum5 merged commit 7559f3d into emscripten-core:incoming Jun 17, 2019
@quantum5 quantum5 deleted the fast-stack-trace branch June 18, 2019 00:21
belraquib pushed a commit to belraquib/emscripten that referenced this pull request Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants