title: Will Project Loom Virtual Threads improve the perfomance of parallel Streams?
body: <p>This is not a duplicate of <a href="https://stackoverflow.com/questions/504103/how-do-i-write-a-correct-micro-benchmark-in-java">How do I write a correct micro-benchmark in Java?</a></p>
  <p>The question goes to the heart of Project Loom design and implementation, and whether the project has been able to speed up the performance of Java Parallel Streams or not. The question is not about bench-marking, it is about intent of Project Loom.</p>
  <hr />
  <p>I am experimenting with Virtual Threads in my <a href="https://github.com/kolotyluk/loom-lab" rel="nofollow noreferrer">loom-lab</a> project, and wanted to see if Virtual Threads are faster than Platform Threads when doing a parallel stream, but it actually seems slower.</p>
  <pre><code>try (var executorService = Executors.newThreadPerTaskExecutor(virtualThreadFactory)) {
      var candidates3 = LongStream.iterate(3, x -&gt; x &lt; count, x -&gt; x + 2);
      time4 = System.currentTimeMillis();
      var primes3 = executorService.submit(() -&gt;
          candidates3.parallel()
              .filter(candidate -&gt; isPrime(candidate)).toArray()
      ).get();
      time5 = System.currentTimeMillis();
  }
  </code></pre>
  <p>where ultimately I get the output (in milliseconds)</p>
  <pre><code>sequential time = 7546
  parallel   time = 1289
  virtual    time = 1388
  </code></pre>
  <p>and in general using Virtual Threads is slower than the common ForkJoinPool. Am I making some basic mistake or misunderstanding somewhere, or has Project Loom not been integrated with Java Streams yet?</p>