r/Clojure • u/pron98 • May 18 '20
State of Loom
http://cr.openjdk.java.net/~rpressler/loom/loom/sol1_part1.html4
u/nezda May 18 '20
When will this be released?
10
u/alexdmiller May 18 '20 edited May 18 '20
Current target is Java 17 I think - I swear I saw that somewhere but can't find the reference anywhere.
1
u/cbleslie May 19 '20 edited Sep 12 '25
trees shocking telephone swim summer resolute cheerful capable snails observation
This post was mass deleted and anonymized with Redact
1
u/leonoelOfficial May 19 '20
The virtual thread thing is a nice POC but I don't really see myself using it, it's too low-level to be used in application space directly and too high-level to serve as a basis for more advanced abstractions. I find a bit disappointing that the loom team chose to reimplement the thread abstraction with the exact same semantics and limitations, providing nothing but an alternative performance tradeoff. For now it's still far behind the current state of the art of JVM asynchronous frameworks, I understand that it's still early stage but the big picture still looks a bit fuzzy to me.
I will evaluate loom when the continuation mechanism will be fully available with cloning support, that's the most elementary block providing the widest range of possibilities, especially the ability to fork a computation arbitrarily across stack frames. TBH I don't quite understand why the loom team doesn't seem to want to release the continuation feature without releasing at the same time its own opinionated green threading tech. Continuations could benefit the entire ecosystem right now, unless I'm missing something the hard part of the job is pretty much done.
7
u/pron98 May 19 '20 edited May 19 '20
it's too low-level to be used in application space directly
Have you read part 2?
Continuations could benefit the entire ecosystem right now
Virtual threads would benefit 99% of the ecosystem, and in a better way than continuations, so we're starting with that.
However, if you give virtual threads a closer look you might find that custom schedulers are, in fact, better than exposing continuations directly. If and when we expose continuations, they will likely be confined to a single thread (virtual or not) because otherwise
Thread.currentThreadbecomes effectful, and the compiler can't hoist it out of loops.unless I'm missing something the hard part of the job is pretty much done.
You're missing almost everything :) Adding continuations to the JDK is the easy part of the job. The hard part is evaluating the industry's needs and constraints, and making sure there's a good product/market fit, and then making the appropriate user-facing design decisions. The goal isn't to show off Java's technical capabilities, but to serve the needs of users of one of the world's biggest, most mission-critical software platform in the best way and under their constraints, so that we deliver the most good to the greatest number of people. This is the really hard part. The technical parts -- continuations, monads -- that's easy student work.
1
u/leonoelOfficial May 19 '20
Have you read part 2?
Yes, and I'm definitely interested to see what you'll end up with. However, I'm also interested knowing what makes you think trio-style structured concurrency is a superior approach compared to functional effect systems, which solve the supervision problem just as much, have more maturity and introduce less accidental complexity.
Virtual threads would benefit 99% of the ecosystem, and in a better way than continuations, so we're starting with that.
If you want to get rid of monadic operators in a traditional streaming system like RX, you need a way to run the current continuation for each value produced by a given stream. Virtual threads are not forkable (yet ?), you can't resume them multiple times from a given suspension point, so they're not helpful here. Do you include all streaming systems in the remaining percent ?
If and when we expose continuations, they will likely be confined to a single thread (virtual or not) because otherwise Thread.currentThread becomes effectful, and the compiler can't hoist it out of loops.
Does that mean there's no chance we'll ever have multishot continuations ? Or that it will be implemented in the virtual thread layer ?
The hard part is evaluating the industry's needs and constraints, and making sure there's a good product/market fit, and then making the appropriate user-facing design decisions. The goal isn't to show off Java's technical capabilities, but to serve the needs of users of one of the world's biggest, most mission-critical software platform in the best way and under their constraints, so that we deliver the most good to the greatest number of people.
That's a commendable goal, but why not leverage the existing ecosystem ? There's already many mature green threading tech running in production now, and they solve real business problems even thought they're so painful to use due to lack of platform-level support (you did a great job describing this problem). They would benefit a lot from direct access to loom's low-level constructs, so what is the point restraining their usage ?
3
u/pron98 May 19 '20 edited May 19 '20
I'm also interested knowing what makes you think trio-style structured concurrency is a superior approach compared to functional effect systems, which solve the supervision problem just as much, have more maturity and introduce less accidental complexity.
I reject your claim, and I think it ultimately comes down to personal aesthetic preferences. I think that, given the low adoption rate for various reactive solutions despite having few alternatives, it is clear what the more popular preference is. Nevertheless, structured concurrency is new, which is why, if we adopt it, we'll do so very carefully.
you need a way to run the current continuation for each value produced by a given stream.
You need to run a piece of code for each value, not necessarily the current continuation. This can be done either with a simple loop reading from a channel, from attaching functional combinators to channels (again, depending on user preference), or by creating a new thread for each element.
Does that mean there's no chance we'll ever have multishot continuations ?
I don't know how to answer this question yet. But as someone who's enjoyed working with multishot continuations for years, I must admit that their marginal benefit over non-reentrant ones is quite small, and they are often used in very cool, but ultimately not very impactful cases. Having said that, they have some uses in things like automatic differentiation, so we'll judge their cost/benefit later.
but why not leverage the existing ecosystem ?
That's exactly what we're doing. The existing ecosystem around threading in Java is several orders of magnitude bigger than the relatively unpopular "reactive" ecosystem.
They would benefit a lot from direct access to loom's low-level constructs, so what is the point restraining their usage ?
As I said, I think that custom schedulers give you more than you even asked for. Study them for a bit :)
1
u/leonoelOfficial May 20 '20
You need to run a piece of code for each value, not necessarily the current continuation. This can be done either with a simple loop reading from a channel, from attaching functional combinators to channels (again, depending on user preference), or by creating a new thread for each element.
A thread is an abstraction of a processor, a channel is an abstraction of a pipe. They're both purely accidental complexity. Have you ever heard a customer say, I want a processor here, I want a pipe there ?
As I said, I think that custom schedulers give you more than you even asked for. Study them for a bit :)
That answer makes it very clear that you did not understand what I asked for.
Anyway, thank you for having taken the time to clarify your vision :
FP is an inferior paradigm because otherwise it would be more popular, and the lack of platform support has nothing to do with it.
There's no point exposing project loom's low-level constructs because virtual threads are the right level of abstraction for every problem.
I wonder what kind of feedback you're waiting for.
2
u/pron98 May 20 '20 edited May 20 '20
Have you ever heard a customer say, I want a processor here, I want a pipe there ?
All code is accidental complexity, in a sense. Have you ever heard a customer say, I want a monad here, I want a continuation there? The question is how easy it is to write, read, debug, profile and maintain code that satisfies the customer's needs. And no one says that you shouldn't write libraries on top of threads and queues to make this stuff as declarative as you like. That's what libraries are for, and the richness of Java's library ecosystem is a great source of pride. We just put the building blocks in the JDK. How to use them is up to you, and our users are spoiled for choice.
Anyway, thank you for having taken the time to clarify your vision ...
Neither of these is my opinion, let alone my "vision," and it's unclear to me where I "clarified" it to be so. I try not to pass a value judgment on aesthetic choices in a professional capacity -- the only way to judge a programming style to be superior or inferior would require some data I don't have -- and I believe threads are the right level of abstraction in the JDK for the specific problem presented in the article. Higher-level constructs might well be provided by libraries, and the JDK could well choose other constructs for other problems.
1
u/daver May 21 '20
So, we’re back to green threads again, ala the mid-1990s. Cool. I’m old enough to remember when OS threads were the new hotness. And then Erlang showed us how to do it right.
2
u/pron98 May 21 '20 edited May 21 '20
Sort of. Green threads + multicore + custom scheduling, and in addition to native threads. But yes, Erlang has absolutely been an inspiration.
1
u/daver May 21 '20
The JVM on Solaris had M on N threads way back when. Multi core was always there for boxes that supported it, but was expensive and not many did. Now multicore is normal. But yes, custom scheduling is new.
Should probably clarify that SMP was supported early (1990s), but not from day 1.
4
u/pron98 May 22 '20 edited May 22 '20
Yes, that was the case for a short while, although the term "green threads" was reserved for the M:1 case. It was a period of many changes and many VMs, so there wasn't really "the JVM." We had:
The Classic VM in JDK 1.0 for Solaris was M:1 ("Green Threads").
The Exact VM in JDK 1.1 and 1.2 for Solaris was M:N, but this wasn't done in the JVM but in the native thread-library on Solaris 8, T1 libthread. Solaris 9 switched to 1:1.
The HotSpot VM in JDK 1.3 for Solaris first supported Solaris 8's T1 with M:N and then, in 1.4 switched to 1:1 ("Native Threads"), making threading more consistent across Windows and Solaris.
1
2
3
u/im_caeus May 18 '20
ZIO, Cats, and anything Haskell I/O monad inspired is pretty cool. At the end of the day, monadic comprehensions could've make all this loom project a less ambitious more affordable challenge (and more versatile, as we could be writing "sequential" code, like JS generators, for anything that has a monadic behavior, like Optional type, immutable lists, Lazy computations, JSON decoders, explicit delimited continuations, and any custom type which could benefit from monadic comprenhensions)
Cool they are making progress, but hiding it under complex core constructs and saying to users "don't wonder how it works, it just does, use it" is a really shitty approach. I wouldn't think developers are not curious about the inner workings of it.
It's like kotlin coroutines. They work internally with "delimited continuations" (quoted, because they are not reusable, which means they are stateful, which means they are not THAT powerful, which means they are not actually delimited continuations (for example, they cannot be used with lists)), but WHO KNOWS?