-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Excessive stack usage when using tokio::spawn
in debug builds
#2055
Comments
I made some changes where I tried inline the whole path from This is the path the code follows:
I then run a simple script to trigger the issue on debug mode, that doesn't happen in release mode: use tokio;
use tokio::task;
const num_tasks: i32 = 1000;
#[tokio::main]
async fn main() {
let data = [0; 110_224];
dbg!(stacker::remaining_stack());
task::spawn(async move {
println!("{}", data[22]);
tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
});
} A gist of the results, and the different different versions of Tokio I'm using for both: All in all, I get to a point where I don't get a stack overflow for that original case. data = [0; 200_000]; in release mode, but not on debug mode, even with the inlining changes applied. So I don't really think we're getting enough from these in-lines. -- |
Description
When using
tokio::spawn
, thetask
to spawn is passed through a number of functions before it is moved to the heap:In my case, I had 150kb of stack space remaining (checked using
stacker::remaining_stack
), and I was passing a 50kb task. So for each stack frame above, 50kb of stack was used until the task was moved to the heap in the form of aRawTask
.This is typically not an issue with optimized builds since most of the stack frames are inlined and the task size is significantly decreased through optimizations. But it might be possible to be nicer towards non-optimized builds by moving the task to the heap as early as possible.
The text was updated successfully, but these errors were encountered: