clojure-dev

seancorfield 2023-09-24T17:42:14.020949Z

JDK 21 is here so we're going to see even more folks trying out virtual threads. There have been posts (here and elsewhere) about problems with synchronized and virtual thread pinning. The Clojure team are aware of this and are maybe looking at using ReentrantReadWriteLock in some places to alleviate this and make Clojure "more compatible" with virtual threads (see https://ask.clojure.org/index.php/12991/request-to-find-and-eliminate-virtual-thread-pinning?show=13004#c13004 for example). At work, we're probably going to be moving to Jetty 12 "soon" and JDK 21 (we're already on JDK 20 with --enable-preview) and we'd like to see how Jetty 12's virtual threads option works... but it sounds like we could run afoul of the synchronized issues... Is there a timeline for addressing this in Clojure? I'm assuming at this point that it's "too late" for this to be addressed in 1.12 but I'm curious whether it's considered a priority for 1.13 or perhaps a 1.12.x interim version?

☝️ 4
Alex Miller (Clojure team) 2023-09-24T17:57:56.135479Z

We are going to discuss more this week (paused due to strange loop :)

Alex Miller (Clojure team) 2023-09-24T17:59:25.213659Z

Still possible we will do something in 1.12, could also do a 1.12.1. I did a bunch of assessment a few months ago

Alex Miller (Clojure team) 2023-09-24T18:00:31.943499Z

The stuff people have been posting is generally overkill but I think lazyseq and delay are probably the two highest priority things

seancorfield 2023-09-24T18:00:45.258279Z

Oh, cool. Thank you! I really thought we might have to wait for another full release cycle.

ghadi 2023-09-24T18:05:30.124839Z

Adding onto what Alex said, it is a non-starter to add a RWLock to every lazyseq cell

ghadi 2023-09-24T18:07:15.284009Z

Lazy seqs are mostly uncontended, and an extra object is a large allocation cost

ghadi 2023-09-24T18:08:35.098099Z

We should endeavor to keep costs off the fast path

ghadi 2023-09-24T18:09:06.228299Z

See lock-free techniques such as https://nullprogram.com/blog/2023/07/31/

🤔 1
seancorfield 2023-09-24T18:09:13.638619Z

Yeah, I trust you folks to make the right trade offs here... and I know this sort of thing is all about trade offs 🙂

ghadi 2023-09-24T18:20:14.828079Z

Are people seeing thread pinning on lazy seqs that are not doing IO?

Alex Miller (Clojure team) 2023-09-24T18:24:24.112009Z

This ^^

Alex Miller (Clojure team) 2023-09-24T18:25:46.571469Z

Would really like to see actually problems rather than just “synchronized bad now” as that helps us make those tradeoffs correctly

1
seancorfield 2023-09-24T18:31:33.987039Z

Heh, well, once Temurin have JDK 21 builds available and New Relic supports JDK 21 and Jetty 12 ("some time next quarter"), we'll try out virtual threads in production and see what -- if anything -- breaks. But seeing folks post "I ran headlong into <this problem> with Clojure and virtual threads..." is why I figured I'd ask 🙂

Alex Miller (Clojure team) 2023-09-24T18:36:26.958409Z

Is that what they’re posting though?

ghadi 2023-09-24T18:38:30.318679Z

I’ve only seen synthetic repros - please tag me if you see a real world issue

seancorfield 2023-09-24T18:46:50.601179Z

"I run a startup and we ran headlong into this synchronized block when using Java 19 virtual threads:" -- https://ask.clojure.org/index.php/12991/request-to-find-and-eliminate-virtual-thread-pinning

ghadi 2023-09-24T20:55:33.753739Z

thanks, commented