Scala is a very sweet language, but many of its abstractions come with hidden costs, so you might sometimes wind up writing some really slick code that is dog-slow, and be wondering where to start.
That’s where VisualVM comes in. You probs already have it installed on your computer. This was an especially pleasant surprise for me as primarily a .NET developer, I’m used to the decent profilers being expensive (my favorite is the one that comes with Visual Studio Ultimate, as I think sampling > instrumenting).
- Start running the code you want to profile inside IntelliJ.
- You’ll see a new java icon, representing the running process, appear under the “Local” section of the leftmost “Applications” pane of VisualVM – right-click the icon.
- From the menu that appears, click “Sample”.
- Now wait a while for it to collect enough data, stop running your program, and you should have a sweet list of the hotspots in your code.
- When you want to dig into a hotspot and figure out the stack trace leading up to it, select it and click the “Snapshot” button. Bam!
Thanks to http://visualvm.java.net/gettingstarted.html and http://stackoverflow.com/questions/1340082/scala-profiler for pointing me to this stuff!