Search code examples
javaperformanceoptimizationprofilingvisualvm

Does profiling in Java bring its own performance issues?


I regularly profile my team's high-performance Java program as inefficient functions can cause major slowdowns. To do so, I keep a port open for attaching Java VisualVM using the following Java machine arguments:

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9011 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost

It struck me today: does profiling a Java program -- or simply keeping a port open for the sake of profiling -- introduce further speed reductions? If so, are some methods of profiling more costly than others? What kind of speed reduction or overhead -- e.g., 1% of runtime, 10% of runtime -- is normal to expect?

While my question is intended for the wider Java audience, I'll note that our program a is memory-light but CPU-intensive simulation: specifically, there are an enormous number of small but computationally expensive function calls being perpetually made. Perhaps optimization is expensive in our case given the sheer number of function calls, but less so for others?


Solution

  • does profiling a Java program

    About 10% - 30% depending on what you are doing.

    or simply keeping a port open for the sake of profiling

    Probably almost no overhead.

    is memory-light but CPU-intensive simulation: specifically, there are an enormous number of small but computationally expensive function calls being perpetually made.

    I would seriously consider FlightRecorder (from Java 7, better in Java 8). This has much lower overhead, and has much more details CPU recording. IN Java 8 you can run it without any command line arguments added.