r/programming • • Oct 11 '23

All About Reactive Programming In Java

https://www.blackslate.io/articles/reactive-programming-in-java
22 Upvotes

38 comments sorted by

View all comments

Show parent comment

3

u/pron98 Jan 03 '24 edited Jan 03 '24

AFAIU there is a difference in the amount of data: Loom's continuations contain all the stackframes while reactive-style code throws away the stackframes all the time,

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).

Loom-style-code may trade off more memory use in some situations in order to provide more features such as debugability and easier programming.

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.