4 ms·
The fact that explicit async turned out to be more complicated than expected is precisely why I'm skeptical of loom. When the magic works perfectly it'll be gre
by lmm 4y ago
The fact that explicit async turned out to be more complicated than expected is precisely why I'm skeptical of loom. When the magic works perfectly it'll be great. When it doesn't...
> If I had a dime for everytime someone made a blocking call from an async function.. And who can blame them? Most blocking functions aren't even documented as such, you just have to know.
Agreed. I'd like to see blocking represented in the type system the same way we do for async, so that you can't mix and match the two unless you deliberately choose to.
- jayd16 4y ago> so that you can't mix and match the two unless you deliberately choose to. Function coloring as a feature?
- lmm 4y agoFunction colouring has always been a good idea, as long as you have a language where you can be polymorphic over it where appropriate (i.e. one with higher-kinded types).
- Quekid5 4y agoThe type of thing Loom is doing has been working great in e.g. the Haskell runtime for decades at this point.
- kaba0 4y agoWhat do you mean? I really don’t think there is anything comparable in Haskell.
- funcDropShadow 4y agoThere is and it has been for quite some time, see chapter 4 of [1]. [1]: Runtime Support for Multicore Haskell, Simon Marlow, Simon Peyton Jones, Satnam Singh (https://www.cs.tufts.edu/~nr/cs257/archive/simon-peyton-jones/multicore-ghc.pdf https://www.cs.tufts.edu/~nr/cs257/archive/simon-peyton-jone...)
- kaba0 4y agoThank you, I stand corrected. Will have to check the linked paper in depth later, but is IO async only or is CPU calculations made automatically concurrent? Last time I checked I don’t remember it being the case for the latter without explicitly requesting it.
- funcDropShadow 4y agoCPU bound calculations are not parallelized automatically. There are some operators (a.k.a strategies) to do that declaratively to pure code and there are monadic libraries to parallelize Haskell code.
- Quekid5 4y agoI'm not 100% sure, actually, but IIRC there is an automatic insertion of 'yield points' into ordinary chunks of Haskell code, so, yes, it will yield automatically even if CPU-bound. Regardless, it's never been a problem in practice. Doing this on the JVM is not possible without actually modifying the running bytecode, so that's why they have that caveat for Loom.
- kaba0 4y agoThat’s the point of loom. You doesn’t need to know whether this something blocks or not, the JVM does know it so it can do the correct thing. Given that the JVM ecosystem is very very pure and barely uses any native calls (where it can’t know about blocking), this will pretty much work automagically everywhere.
- funcDropShadow 4y agoMy understanding of Loom is, that it is loosely inspired/similar to GHC's runtime. In both every blocking call into a system call is replaced with an equivalent asynchronous system call and some internal thread will manage all those things to wait for. While the operating system is processing the asynchronous request the lightweight thread which made a seamingly blocking call is put aside and some other lightweight thread can execute on the same OS/level thread. Since the JVM comes with all the blocking call in its own standard libraries, it can rewrite them all internally. Every third-party library that uses the normal Java standard library will benefit from this under the hood replacement of blocking systems call with non-blocking system calls. Only when you use other native libraries you have to be careful to use mostly non-blocking functions. Therefore Loom allows programmers to think and program with blocking calls, but they get the performance characteristics of non-blocking calls. That is awesome. And there is no need to use function colouring or type-level encoding of blocking/non-blocking code.