Tip: Netbeans 6.x scanning performance fix
I use Netbeans as my primary editor. It's a great editor with pretty much all the features I would want built in (zero-configuration Mercurial support, code completion+navigation, unit testing support and more) .
The only caveat has been the performance - I was so frustrated I installed (and ultimately rejected) the vast majority of other (PHP) editors. There is a simple fix if you have memory to spare: increase the heap size in the startup options. The Java VM default heap size seems to be way too small, causing a lot of swapping within the Java VM (while not using all the memory available from the OS perspective).
Fixing Netbeans scanning performance
Open /etc/netbeans.conf (e.g. C:Program FilesNetbeans 6.xetcnetbeans.conf). If you are on Windows 7, you need to start your text editor with Administrator privileges (right click and select Run as..).
Change the line: netbeans_default_options="-J-client -J-Xverify:none ...."
by adding the following to the single line (AFTER "-J-client -J-Xverify:none"):
-J-Xmx2048m -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled
-J-XX:+CMSPermGenSweepingEnabled
The -Xmx option changes the maximum heap size the Java virtual machine can address to 2048M from the default value (which is a "best guess" method). The other three are explained in the conf file.
DONE! Ever since I made this tweak (about two months ago) there have been no additional pauses at all. My theory is that the Netbeans scanning code was exhausting the heap, and a majority of the time "scanning" was instead spent dealing with the heap exhaustion. Now I will not say that it is reasonable for an IDE to consume 2 gigabytes of memory - but if that's what it takes to fix performance, fine.
Comments
Petr Jiricka: Hi, thanks for blogging about this. We would like to fix the problem so you don't have to do this workaround. Can I ask:
- Is your experience based on NetBeans 6.7.x or 6.8 RC1? We made significant improvements in NB 6.8, so can you please try whether it behaves better out of the box?
- Can you be specific about how big is your project (number of files), and how long the scanning takes+how often you face the problem? We regularly test performance on mid-size projects, but it is true that there can be problems for huge projects.
- Can you tell us about your hardware? I.e. size of memory, processor etc? Also, do you store your source files locally, or on a remote/network drive?
- Can you test the performance of working with your project outside of the Mercurial tree? I.e. if you export the sources from Mercurial and then point the IDE at the exported sources (and closing the project inside the Mercurial tree).
Thanks for your help - if you like, you can send your replies to my e-mail petr.jiricka at sun dot com.
Petr
Mikito Takada: Hi Petr,
I am stunned that you responded so quickly, and very glad to hear that the Netbeans team is actively working on the issue (and clearly keeping a Google Alert on Netbeans!).
1) My experience is based on Netbeans 6.7, and at least for 6.8 Beta I had the same issue. I installed 6.8 RC1 yesterday, so I will have to see if the issue still occurs without the workaround, and update the post accordingly in a few days.
2) The projects are about 2000 - 5000 files excluding Mercurial directories. On 6.7, the scanning used to take random amounts of time (sometimes minutes, sometimes hours unless stopped). With the fix, the time went down to to mere seconds. Will see with 6.8RC1.
3) Core i7-920 + 6GB memory with source files stored locally on what I would imagine is a 7200rpm drive.
4) Will see later and post an update here.
AdamO: I was having the same problem with Netbeans 6.7.1... I have my source folder (9000+ files) mounted over sftp via Webdrive (caching enabled). Scanning was taking forever and locking up the rest of the app, making it impossible to do anything until after scanning had stopped. I just tried 6.8RC2 and scanning still takes a while, but at least it doesn't lock up everything else. Now I'm able to work comfortably with the scan in progress.
Adam Overlock: I also noticed there's a "Scan on Demand" plugin available for 6.8RC2, allowing you to disable automatic scanning and run it when you want it to run.
Randy: If scanning was properly implemented in Netbeans, it would be in a discrete thread, prioritized lower than the app. It's insane that when it scans, you can't do anything else. Yes, in 6.8 this happens.
I have a quad core, and the app is locked scanning with less than 5% cpu usage.
R
Mike: I have the same issue with 6.8. The CPU usage is not always high, but the UI is so slow it is unusable. I am going to try upping the heap. Thanks for the post.
Tres Finocchiaro: I'm experiencing this on Windows 7 Enterprise x86 single core CPU. I will try the suggested work-around, however I agree with the Netbeans developer that fixing this as part of the release cycle makes it better for stuff like upgrading.
The release information: Product Version: NetBeans IDE 6.8 (Build 200912041610) Java: 1.5.0_22; Java HotSpot(TM) Client VM 1.5.0_22-b03 System: Windows 7 version 6.1 running on x86; Cp1252; en_US (nb) Userdir: C:Userstfino.netbeans6.8
-Tres
hemuman: My problem Solved with "Scan on Demand". It use to scan for ages.... thanks Adam Overlock
Roy: But if you use Scan on demand, you indexes could be out of date and could cause some lost of data.
Bruce: I also noticed there's a "Scan on Demand" plugin available for 6.8RC2, allowing you to disable automatic scanning and run it when you want it to run.
g: that's right!
combination of enabling Scan On Demand Plugin and also disabling Mercury Plugin
make our CPU Usage more safer... and lower of course... glad to hear everything is now stable... :D
Thorsten: Thanks for this article. The CPU usage of netbeans was realy horrible.
Noe after changing the config it is realy usable. Maybe I will try the scan ondemand plugin later.
thanks
Rob Haag: Thank You! Just got a Win. machine (linux nerd myself)...same issue for me...even now using NB 7.1 on Windows 7 (64bit). Have a 2 core (intel 6200) w/ 4gb of RAM...your fix made a huge difference. I'm remoting to my Linux box so I can take the show on the road now and again, but even with a local project (empty) the 'scanning' was hanging forever on 100% mark.
Raja: Friends, I also affected by the Scanning Projects issue. after i installed the Scan on Demand plugin also can't solved this. Finally i removed my - Project - right Click -> Project Properties - removed one big folder(user_java- under this all the project files here). then only solved this issue. So pls just check for this small pin pbms and corrected.
Thanks, CRT.