Consider:
let title = String::from("Hello");
let response = fetch_notes().await;
display(title, response);
At the .await, the compiler knows exactly what must survive: title and the unfinished fetch. Conceptually, it generates storage like:
struct PausedTask {
title: String,
fetch: FetchFuture,
resume_at: State,
}
If fetching isn’t ready, the task stores that state and returns normally to Tokio. Tokio calls another task. Resuming means calling the first task again and continuing from its saved state.
Now imagine the OS interrupts ordinary code halfway through:
let total = calculate_price(items);
It might stop inside calculate_price, inside another function it called, midway through evaluating an expression. Intermediate values may occupy CPU registers, and several function calls may be active on the stack.
The OS preserves the machine execution state, leaves that thread’s stack intact, schedules another thread, and restores its execution state.
The key savings are:
• Async uses a normal return and another function call, without requiring a kernel scheduler transition.
• The compiler stores only values needed across known suspension points.
• Tasks don’t each require a dedicated OS-thread stack.
It’s less “saving registers is terribly expensive” and more “a known pause point permits a simpler mechanism.” Async can still be slower for some workloads; its main advantage is handling lots of waiting operations efficiently.