pub fn min_stack_size() -> usizeExpand description
Running out of stack has been an issue for us. We box types and futures in various places to mitigate this.
Main thread stack-size has a BIG variety here across platforms and it’s harder to control (which is why Rust doesn’t by default). Notably on macOS and Linux you will typically get 8MB main thread, while on Windows you will typically get 1MB, which is tiny: https://learn.microsoft.com/en-us/cpp/build/reference/stack-stack-allocations?view=msvc-170
To normalize this we just spawn a new thread called main2 with a size we can set
ourselves. 2MB is typically too small (especially for our debug builds), while 4MB
seems fine. This value can be changed with UV_STACK_SIZE, with a fallback to reading
RUST_MIN_STACK, to allow checking a larger or smaller stack size. There is a hardcoded stack
size minimum of 1MB, which is the lowest platform default we observed.
Non-main threads should all have 2MB, as Rust forces platform consistency there, but even then stack overflows can occur in release mode (https://github.com/astral-sh/uv/issues/12769), so rayon and tokio get the same stack size, with the 4MB default.