sentry-rust icon indicating copy to clipboard operation
sentry-rust copied to clipboard

feat: reduce stack-size of threads

Open thomaseizinger opened this issue 8 months ago • 4 comments

Certain environments like iOS are very resource-constrained. A network extension on iOS is allowed to at most consume 50MB of RAM. By default, a thread in Rust allocates 2MB of RAM for the stack of the new thread. This can be tweaked if one knows that the particular thread doesn't need as much RAM.

thomaseizinger avatar Apr 22 '25 09:04 thomaseizinger

I am opening this as a starting point for a discussion. The implementation is purposely very minimal for now. I am happy to extend with comments, consts etc.

I wanted to discuss first if this is something that you'd be willing to merge.

thomaseizinger avatar Apr 22 '25 09:04 thomaseizinger

I checked all of these threads on a high-level and none of them looked like they would consume a lot of stack-size. ~So I set it to 100KB for all of them which should be plenty for what we are doing in these threads.~

Edit: Ha, it looks like sentry-transport needs more than that.

thomaseizinger avatar Apr 22 '25 09:04 thomaseizinger

I think this is reasonable. As you commented, running a full tokio runtime for usage with reqwest is still quite heavy on stack usage though.

500KB seems to allow CI to pass. I can experiment a bit more to see if we can get it any lower although it is already a great improvement :)

I am not too familiar with the test setup in this repo. Are they exhaustive enough that we hit all scenarios of stack usage and can therefore trust that green CI means we have enough stack for all situations?

thomaseizinger avatar Apr 22 '25 21:04 thomaseizinger

TBH, I wouldn’t put too much trust in them. In particular, I’m not even sure whether we are even testing the http interface at all, or just relying on a mock transport for tests mostly.

Swatinem avatar Apr 23 '25 06:04 Swatinem