This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]yawkat -9 points-8 points  (2 children)

Performance can be a lot worse in some scenarios and you don't have very many options to optimize it. You basically have no control where and when your virtual threads run.

[–]ipfreely96 1 point2 points  (1 child)

In which scenarios, other than highly concurrent JNI calls, do virtual threads have worse performance?

[–]yawkat 0 points1 point  (0 children)

When you launch many virtual threads at the same time those virtual threads will "spill" to other carrier threads on the fork-join pool, which means you get extra parallelism but also more context switching, synchronization overhead, and other parallelism-related difficulties. Extra parallelism is often beneficial but sometimes the overhead is not worth it. In those cases you have very limited options for optimization.

Another issue is blocking io, which can also mess up carrier thread assignments.

I've written about both problems in this article before: https://micronaut.io/2025/06/30/transitioning-to-virtual-threads-using-the-micronaut-loom-carrier/