Hacker News new | ask | show | jobs
by matheusmoreira 19 days ago
> I really don't understand why GC-based languages decided to go with stackless coroutines

From what I've read it's due to a general idea that stacks use a lot of memory, which limits how many of them can be spawned. It's only good if it scales to a million concurrent users. A million 16 KiB stacks is over 16 GiB.

1 comments

But if you have stack growth, the way Go does it, then the stack you allocate is actual memory you use. You are just trading heap allocations for stack growth. I started to see the stack as a super fast allocator that is always available.
Indeed. I think stacks are pretty great myself. Even the memory usage example I gave, which is the typical argument towards stackless, evaporates when the stacks are small. I benchmarked typical stack frames in my language at around 100-300 bytes. Chatting with Erlang/BEAM folks also revealed their stacks were in the same order of magnitude.

I think the popularity of event loops stems from the fact Node does it. Pretty much cooperative multitasking by another name. Functions are coroutines, return is yield and the event loop is the scheduler.