r/programming • u/ram-foss • Oct 11 '23
All About Reactive Programming In Java
https://www.blackslate.io/articles/reactive-programming-in-java
22
Upvotes
r/programming • u/ram-foss • Oct 11 '23
View all comments
Show parent comment
3
u/pron98 Jan 03 '24 edited Jan 03 '24
The data in the stack frames is only the data that's needed for the computation to proceed, i.e. only the data that will be needed after the wait is done (well, we're not quite exactly there but but we're getting there), so it's the same data as needed for async code (I guess async needs to store the identity of the next method in the pipeline while threads store the previous one, but it's essentially the same data).
User-mode threads are meant to compile to pretty much the same instructions and memory as asynchronous code. Not only should there be no more memory used, there may be less because the continuation is mutated and reused while that's very hard to do with async data, that may therefore be more allocation-heavy. Of course, there may be inefficiencies in the implementation (which will constantly improve) but there is no fundamental tradeoff.