eclipse-jdt / eclipse-jdt/eclipse.jdt.debug
Short-lived virtual threads are 1000x slower to create when run in Debug
- Dominant language
- Java
- Stars
- 23
- Forks
- 68
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 13
Description
We are looking at replacing our overly complex multithreading task system with virtual threads in our game engine. Unfortunately, this issue makes short-lived virtual threads more or less useless for us as a replacement for pooled executors, as we cannot achieve realtime speeds in Debug using them.
## Steps to reproduce
```Java
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
public class VirtualThreadTest {
public static void main(String[] args) {
while(true) {
test();
}
}
private static void test() {
AtomicInteger integer = new AtomicInteger();
ThreadFactory factory = Thread.ofVirtual().factory();
//ThreadFactory factory = Thread.ofPlatform().factory();
int levels = 23;
runThread(levels, factory, integer);
long startTime = System.nanoTime();
int limit = (2 << levels) - 1;
int count;
do {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
count = integer.get();
long timeTaken = System.nanoTime() - startTime;
System.out.println(count + " (" + 1_000_000_000f * count / timeTaken + " threads per second)");
}while(count < limit);
}
private static void runThread(int level, ThreadFactory factory, AtomicInteger integer) {
integer.getAndAdd(1);
if(level > 0) {
factory.newThread(() -> runThread(level-1, factory, integer)).start();
factory.newThread(() -> runThread(level-1, factory, integer)).start();
}
}
}
```
## Results
- In Run mode: 1.2249853E7 threads per second
- In Debug mode: 14427.094 threads per second
- Note that the exact numbers here depends on the CPU being used; the point is that the Debug speed should be as close to the Run speed as possible.
## VIsualVM sampling
Here a VisualVM screenshot of Eclipse while the test program above was running:

It would seem that Eclipse is bottlenecking the application by not being able to process all the threads being created fast enough. This theory seems plausible, as in Run mode I get 100% CPU load from the test program, while in Debug I only get 20% CPU load from the program and 100% load on one CPU core from Eclipse.
## Additional info
- Eclipse IDE Version : Version: 2025-03 (4.35) Build id: I20250117-1800 (completely fresh install in a new workspace)
- OS: Windows 10 64-bit
Contributor guide
Assessment
This issue has not been assessed yet.