Rust/wasm32 call stack limits

In my current understanding of Rust, every time we make a function call the following happens:

  • we push a new frame
  • this new frame contains the locals of the function being called + args + some aux data (like return address)

Now, I believe the stack has some builtin size. Thus, my questions:

  1. what are the builtin limits on wasm32
  2. can we change this ?

There's a feature that is much easier to write recursively rather than iteratively (manually using a Vec to fake a callstack in paritulcar). I want to know what the practical call stack limits are on wasm32.

That varies per implementation, but in my experience at around 512KB it's tight enough to avoid recursive code for any project that I want working on WASM.

It's a major pain in the butt to emulate recursive code manually by using a stack, but it's outside of the control of the Rust developers and thus cannot be fixed by them.

The proper solution is to 1. Add an API to the WASM standard that explicitly allows enlarging the stack and 2. have the various browsers and WASM implementations implement that.

1 Like