23

I realize that Java code will slow down when run in debugger.

Question is, will the code slow down simply by starting Java with these options:

Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n

??

Or does the slowdown only happen when you connect to the "debug port" and actually step through code using an IDE?

Community
  • 1
  • 1
Marcus Leon
  • 55,199
  • 118
  • 297
  • 429

3 Answers3

17

First, to strictly answer your question - at least as stated in its title - -Xdebug only enables debugging support in the VM using JVMDI in JVMs prior to 5.0. So in itself, it doesn't do much. Moreover, JVMDI is deprecated since 5.0 in favor of JVMTI:

-Xdebug
Start with support for JVMDI enabled. JVMDI has been deprecated and is not used for debugging in J2SE 5.0, so this option isn't needed for debugging in J2SE 5.0.

So -Xdebug doesn't do anything anymore and the important part is:

-Xrunjdwp:<name1>[=<value1>],<name2>[=<value2>]...

or, starting with Java 5.0, the newer (that you should prefer as the JDWP agent in 5.0 uses the JVM TI interface to the VM rather than the older JVMDI interface):

--agentlib:jdwp=<name1>[=<value1>],<name2>[=<value2>]...

Now, to my knowledge, just loading the jwdp agent and/or configuring the JVM to listen for a socket connection on a given port don't have any noticeable performance impact. But connecting a debugger does.

kris
  • 23,024
  • 10
  • 70
  • 79
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 2
    Even loading the jwdp agent without attaching a debugger [can have a performance penalty](http://developer.amd.com/resources/documentation-articles/articles-whitepapers/java-performance-when-debugging-is-enabled/). – nodmonkey Feb 11 '14 at 21:33
  • 1
    There is an opposite opinion https://stackoverflow.com/a/2195731/657723 – Ivan Balashov Apr 12 '18 at 14:32
11

Performance testing results at AMD indicate that simply enabling the debug agent via the JVM commandline does cause performance degradation regardless of having a debugger connected to it, and that the degradation can be quite large depending on the workload:

Note that we weren’t actually attaching a debugger when we were measuring performance, so we had assumed this agentlib option would be performance-neutral in this usage scenario. When we removed this option, both the CPU utilization and the performance on this workload (measured in requests handled per second) improved dramatically.

See their report:

http://developer.amd.com/resources/documentation-articles/articles-whitepapers/java-performance-when-debugging-is-enabled/

Above link is dead, here's a web archive link of it: https://web.archive.org/web/20160316201129/http://developer.amd.com/resources/documentation-articles/articles-whitepapers/java-performance-when-debugging-is-enabled/

Sammy Guergachi
  • 1,986
  • 4
  • 26
  • 52
Roberto Olivares
  • 1,053
  • 1
  • 11
  • 19
  • When the JVM process runs for long (some days/weeks), slow down is definitely visible. My context: GWT application with Oracle backend, Java 7 on Solaris Zone. – Yves Martin Apr 28 '15 at 09:34
  • 1
    The AMD article has dropped off the web, but can stil be found in the wayback machine here : https://web.archive.org/web/20160316201129/http://developer.amd.com/resources/documentation-articles/articles-whitepapers/java-performance-when-debugging-is-enabled/ – tul Nov 27 '17 at 22:52
1

No, simply enabling the debugging port will have no effect on runtime performance. At least I've never noticed any.

..

jarnbjo
  • 33,923
  • 7
  • 70
  • 94
  • that's not the question he is asking, he's talking about launching the JVM with debug options – Valentin Rocher Feb 10 '10 at 21:13
  • @Valentin - huh? What? Please explain why the command lines don't enable a debug port and hence answer the query. – Egwor Feb 10 '10 at 21:17
  • ok, seems like I had a sudden case of "shit in my eyes"...@jarnbjo : could you just make a void edit to your answer, so I can remove my downvote ? – Valentin Rocher Feb 10 '10 at 21:21
  • 1
    @Valentin No, you didn't, the initial answer was *"The presence of debugging information in the class files will only increase the class file size and has no impact on runtime performance. At least not with current VMs."*. This was not an answer to the question. – Pascal Thivent Feb 10 '10 at 21:37
  • I did in fact misread the question and was a little bit too quick to answer, but edited my answer when I realized my mistake. I'm not sure why the edit does not show though ... – jarnbjo Feb 10 '10 at 21:41
  • @jarnbjo, what does trigger the slow down? – Marcus Leon Feb 10 '10 at 21:57
  • oh ok thanks @Pascal, thought I was hallucinating. Removed the downvote anyway. – Valentin Rocher Feb 10 '10 at 22:33