StuPointerException
StuPointerException

Reputation: 7267

Why do method breakpoints impact performance so negatively?

Why does adding a method level breakpoint have such a negative impact on program performance in debug mode?

Take the following (somewhat contrived) example:

public static void main(String[] args) {
    long start = System.currentTimeMillis();
    for(int a = 0; a <Integer.MAX_VALUE; a++) {
        long v = a * a;
        if(v == 100) {
            doSomething();
        }
    }
    System.out.println("Time: " + (System.currentTimeMillis() - start) + " ms");
}

private static void doSomething() {          //*** BREAKPOINT 2
    System.out.println("done something");    //*** BREAKPOINT 1
}

The performance of this is approximately:

What's going on? What benefit does the method level debug give us that normal ones can't?

Thanks!

EDIT

The timings are only approximations and include the time it takes me to react to the breakpoint and continue the application (which looks to be roughly about 1 second).

I appreciate that System.currentTimeMillis() is not 100% accurate, however the results are consistent over multiple tests and the difference in performance is massive! In fact, adding the method level breakpoint results in a warning from IntelliJ that it will have an impact on performance.

Upvotes: 13

Views: 2933

Answers (2)

Smartik.NET
Smartik.NET

Reputation: 136

Recently I made a research regarding Method Breakpoint Slowness issue. My conclusion was that the root issue is that Method Breakpoints are implemented by using JDPA Method Entry & Method Exit feature. This implementation requires the JVM to fire an event each time any thread enters any method and when any thread exits any method.

click here to read the entire article

Upvotes: 9

Akash Thakare
Akash Thakare

Reputation: 22972

According to Eclipse Help

While the breakpoint is enabled, thread execution suspends before that line of code is executed. The debugger selects the thread that has suspended and displays the thread's stack frames. The line where the breakpoint was set is highlighted in the editor in the Debug Perspective.

So according to me this may be the reason of this delay.

Upvotes: 0

Related Questions