为什么方法断点会对性能产生如此负面的影响? [英] Why do method breakpoints impact performance so negatively?

查看:191
本文介绍了为什么方法断点会对性能产生如此负面的影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在调试模式下添加方法级断点对程序性能有如此负面影响?

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
}

它的性能大约是:

  • 不在调试中:4.5秒
  • 调试,断点1:6.0秒
  • 调试,断点2: 47.0秒

这是怎么回事?方法级调试为我们提供了普通方法不能提供的好处?

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

谢谢!

编辑

这些时间只是近似值,其中包括我对断点做出反应并继续执行应用程序所花费的时间(大约为1秒左右).

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).

我很欣赏System.currentTimeMillis()并非100%准确,但是在多个测试中结果都是一致的,并且性能差异很大!实际上,添加方法级别断点会导致IntelliJ发出警告,警告它会影响性能.

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.

推荐答案

最近,我对方法断点慢度问题进行了研究. 我的结论是,根本问题是方法断点是通过使用JDPA方法条目和方法来实现的.方法退出功能.此实现要求JVM在每次任何线程进入任何方法时以及任何线程退出任何方法时均触发事件.

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.

点击此处阅读整篇文章

这篇关于为什么方法断点会对性能产生如此负面的影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆