Virtual Threads performance

Attila Kelemen attila.kelemen85 at gmail.com
Wed Apr 5 09:13:45 UTC 2023


>  All actions are working inside the single benchmark platform thread

Wow, I should have noticed that given that I have tried replacing
"sleep" with `consumeCPU`, and then Loom outperformed coroutines by a
factor of 4 on my 4 core CPU ...

Anyway, given this, I have replaced the dispatcher of `coroutines`
with `Dispatchers.Default` (meaning that all tests are now using the
same number of threads), and with my modifications of waiting on a
`CountDownLatch` / `Semaphore` released after 10 ms, and parallel task
submission. I got the following results:

Benchmark                    (delay)  (repeat)  Mode  Cnt    Score
Error  Units
LoomVsCoroutines.coroutines       10    100000  avgt    5  130,491 �
2,073  ms/op
LoomVsCoroutines.hybrid           10    100000  avgt    5  122,486 �
10,191  ms/op
LoomVsCoroutines.loom             10    100000  avgt    5   92,807 �
16,310  ms/op

So, the moral of the story is that JMH outputs "REMEMBER: The numbers
below are just data. To gain reusable insights, you need to follow up
on
why the numbers are the way they are." for a reason :)

Attila


More information about the jdk-dev mailing list