emscripten-core / emscripten-core/emscripten
Should remove remove (reduce usage of) withStackSave?
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
The `withStackSave` helper is a convenient way to avoid having the remember to write `stackRestore` at the end of a JS library function.
However, this construct has some cost. Firstly it create an inner closure object, and secondly it relies on `try/finally` control flow to restore the stack pointer.
At the time when I originally wrong `withStackSave` I was under the impression that restore in the stack, even in the exceptional case, was important. However, my new/current understanding is that the shadow stack pointer doesn't need to be restored during unwinding until an exception is caught. i.e. its up the outer try/catch to return the stack pointer.
The other useful think about `withStackSave` is that for function with multiple exit points one doesn't need to repeat the `stackRestore` statement for each one. Perhaps for such functions we can keep this helper around, but I suspect that are few functions that have enough exit points to justify this helper.
Contributor guide
Assessment
This issue has not been assessed yet.