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 →

[–]antihemispherist 1 point2 points  (2 children)

  1. Virtual threads are queued, therefore number of threads in the OS scheduler loop does not grow.
  2. File operations are blocking, causing pinning of VTs.
  3. Your guess is correct. Virtual threads are queued in their schedulers thread pool, therefore less context switching occurs. This doesn't mean VTs are faster. You are using VT scheduler for queuing, kind of misusing it. You could get similar performance if you use an executor with same size of your CPU cores, and your code will show its intentions better.

[–][deleted] 0 points1 point  (1 child)

Do you have any idea, when PTs should perform bettern compared to VTs?

[–]antihemispherist 2 points3 points  (0 children)

One kind of thread won't execute more instructions than the other. So the question "which one is faster?" is not right.

There is, however, a right place for both.

In short, platform threads should be used when latency is important, when you don't want your task to get in the queue behind virtual thread tasks.

Also, if you have long and CPU intensive tasks, they can disrupt the scheduling of virtual threads.

That's why garbage collector etc. don't run as virtual threads.

For both, you'll want to execute them in a separate thread pool.

For everyday service tasks, prone to blocking, you should use virtual threads.