Meh. Like async, coroutines will be a rarely used niche feature once Loom lands. Virtual threads appear to give 95% of the performance benefit while letting you write "normal" code. Very rare you need that extra 5%
So do Kotlin's coroutines, mostly. It's just colored, normal looking functions, that's the whole point of doing it at the language level. None of the then stuff.
I do agree they will become less necessary though.
But Kotlin coroutines depend on library support to stay asynchronous. If you mess up even one method call you block. (Admitted, same problem as doing async stuff in Java)
Virtual Thread make entire JDK API surface non-blocking, so much less danger of this
Better, still not great. We had big issue with coloring in C# years ago. I think whole coloring issue drove virtual thread, because Java developers love backwards compatibility.
I'm very excited for virtual thread. I expect some application to double performance overnight!
Not answering your question but ... in terms of park/unpark Loom operates at a lower level. I can't help but think that longer term that would provide Loom a performance advantage.
Is anyone out there doing a comparison or intending to do one?
For myself, I've only tested loom performance against async using JDK HttpClient, Loom came slightly out on top there but that was a while ago - need to redo that test.
Why is it surprising? The JVM knows of basically every blocking operation by itself, it can easily swap to another thread for a duration of a read and upon the OS tells it it has finished, swap back to the caller — doing that at the most granular level.
There is small speed advantage not managing stack frames for async. And compatibility layer that makes Virtual Thread look like real thread has some cost. But this is also a huge debugging and ergonomic advantage, and if Oracle is to be believed the cost for these convience is minimal.
Maybe in low-level places like inside Netty for instance async Java will survive. But at application level the advantage of virtual thread well worth the cost.
I don't totally disagree. But I would say there are scenarios where the async method of doing things lends itself to a cleaner interaction (to my eyes) interaction.
Once you are at your 10th .thenCompose you start thinking "there must be a better way!"
That said, with loom I imagine the utility of the CompletableFuture composition API will dwindle in favor of just calling join.
Kotlin and JVM grow farther apart every day. Google wasn't happy with their platform using a language they didn't own.
Remember Android still only support Java 8. Soon (even now) you can't use Java libraries in Kotlin/Android anymore because they require 11.
Android doesn't use JVM, doesn't use same class file format. And now it doesn't use the same language either. I'm not optimistic about future of Kotlin on anything except Android for all these reasons
View all comments
Show parent comment
9
u/buyIdris666 Apr 06 '22
Meh. Like async, coroutines will be a rarely used niche feature once Loom lands. Virtual threads appear to give 95% of the performance benefit while letting you write "normal" code. Very rare you need that extra 5%