Re:How Rust optimizes async/await
by newacctjhro on Monday August 19, 2019 @09:12PM
(#20743063)
Go needs to allocate a growing stack on the heap, needs to move it around, etc. It's not as efficient as Rust's async.
[ Parent
| on HN ]
But is it as efficient or more than the linux threads?
Re:How Rust optimizes async/await
by littlestymaar on Tuesday August 20, 2019 @09:56AM
(#20747082)
I don't have the full answer (and I would love if someone more knowledgeable could jump in this thread) but I'd say it depends since there are a few antagonistic effects :
- goroutines are (unless it changed since last time I used it) cooperatively scheduled. It's cheaper than preemptive scheduling, but it can lead to big inefficiencies on some workload of you're not careful enough (tight loops can hold a (Linux) thread for a long time and prevent any other goroutines from running on this thread).
- goroutines start with a really small (a few kB) stack which needs to be copied to be grown. If you end up with a stack as big as a native stack, you'd have done a lot of copies in the process, that wouldn't have been necessary if the stack was allocated upfront.