News for hackers. Stuff that matters.
Re:Java 21: The Nice, the Meh, and the Momentous by logicchains on Friday September 22, 2023 @04:36PM (#37617431)
Do you know if clojure will be adopting these virtual threads, or still using the macro-based approach?
Re:Java 21: The Nice, the Meh, and the Momentous by bcrosby95 on Friday September 22, 2023 @05:22PM (#37617953)
You can adopt them yourself in Clojure by changing the executors Clojure uses. You can do this for both agents and core.async.

In my use case, when I tested this, core.async + virtual threads had some slight performance benefits over agents + virtual threads, but since core.async relies on macros the error messages can be hairy.

Thus I prefer to use agents. But my use case involves tens of thousands of these things.

Re:Java 21: The Nice, the Meh, and the Momentous by bcrosby95 on Friday September 22, 2023 @08:30PM (#37619506)
It depends upon what you mean here.

You could always set the backing thread pools for core.async and agents in Clojure. That gives you the ability to use virtual threads right now.

But in order to avoid thread pinning, there will need to be some code changes to convert some uses of synchronized to ReentrantLock. How fast that happens will depend upon the given library maintainer. Here's an issue for making some of these changes in Clojure's core library: https://clojure.atlassian.net/browse/CLJ-2771

I've tested Clojure's agents with the new virtual threads for my targeted use case they're significantly faster than before - I can spin up tens of thousands of mostly idle agents and reach performance close enough to core.async for me.