domenica 3 marzo 2013

Eclipse CDT Linux Howto


UPDATE 5 March 2013: I confirm, Juno CDT has done few improvement.. but when doing a real job, restarting eclipse once every hour isn't handful.. and it is still too much slow (this is my opinion after few days of real use). My opinion is that Eclipse CDT Juno is not the best solution for working with C/C++ and being productive.

UPDATE 3 March 2013: Eclipse CDT performance looks better after the last IDE update. After 3 hours Xorg still raises cpu usage and things slow down but it is far far better.


Eclipse CDT looks a great c/c++ IDE but, with default settings, is unusable is very slow in Linux; The main issues about default configuration, are:
  • memory consumption, gc slowness
  • Xorg (linux) cpu usage, more slowness
  • very very slow
  • slowness
  • bugs which causes crashes
Using Eclipse CDT is a pain and it looks unusable (Intel Q9300@2500 Core2Quad, 8GB and SSD);I have fine-tuned the default configuration accordingly to this guide and other stackoverflow answers in order to solve these issues.

Let's fix it!

Edit eclipse.ini and raise the VM memory settings, these are mine (I have 8GB of ram so these values are a bit exaggerated, by default I am allocating 2 Gbytes for eclipse):

-Xss2m
-Xms1024m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:PermSize=1024m

Raising these values may help GC (Garbage collector). Perhaps, I have noted less ide assertions and errors.

Eclipse linux Theme support is a useless mess, GTK+-Qt is buggy and has lots of leaks which causes Xorg to eat up all your cpu, disable the GTK-Qt theme support.
Execute eclipse, go into Windows->Preferences->General->Appearance and set the Theme to Classic (If you know a better way please give me feedback) 

There is an old bug which causes Eclipse CDT to crash suddenly, add this line (vm configuration) in eclipse.ini :

-XX:-UseCompressedOops 

Tune the CDT settings in order to be less aggressive (CDT has to self parse the sources), I have adopted only few changes, let's quote form guide (I suggest to read ALL the guide, it is useful when working on big projects):
Whenever you create a new workspace for a Mozilla source tree, you should be sure to turn off the following two settings in the workspace preferences (Window > Preferences, or Eclipse > Preferences) before creating a project in that workspace:
  • in "General > Workspace", disable "Build automatically"
  • in "C/C++ > Indexer", disable "Automatically update the index"
Turning off automatic indexing prevents the CPU intensive indexer from running at various stages during the steps below before we're ready.
Warning, thanks to this change, while developing, you need sometime to trigger indexing manually (right click on the project, Index->Rebuild).

You can also configure your project properties in order to enable multicore compilation: Project Properties_> C/C++ Build -> Behavior -> Enable Parallel builds

Conclusion

The fine tuned Eclipse CDT  looks usable, there are no hangs; The IDE still slow down during the programming sessions and became very slow in 1 or 2 hour.


UPDATE: I feel like my how-to is a workaround, in fact it seems there are issues with Eclipse UI performance in Juno, let's look here