7 Tips to Speed Up Eclipse

About a month ago, I published a blog about the love and hate of Eclipse . Some people asked me how to speed up Eclipse, and this article discusses that. By the way, this article is not comparing IDEs, so don't say you hate one IDE and choose another. This article just focuses on how to make Eclipse run faster. Each tip is detailed for Windows, Linux, and MacOS users. After using all the optimization tricks, Eclipse should start up in 10 seconds and run more smoothly than before.

These tricks not only shorten the Eclipse startup time, most of them also improve the user experience. For example, open classes faster, jump from one definition to another, view javadoc, etc. But these speedups cannot be accurately measured in time, so there is no specific benchmark for the speedup effect of each trick.

Tip: It is assumed that you have installed a solid state drive and have at least 8Gb of RAM. If not, the performance gain may not be large.

Tip 1: Run the latest version of JDK and Eclipse

Usually, new versions of JDK and Eclipse will have performance optimizations. Make sure you are using 64-bit Eclipse and using Oracle's JDK. For web development, you need to use Eclipse for Java EE instead of Eclipse for Java.

Put Eclipse and workspace on the SSD. Start Eclipse.

Tip 2: Adjust Eclipse Preferences

  • General > Startup and Shutdown : Removes all plugins loaded at startup.
  • General > Editors > Text Editors > Spelling : Turn off spell checking.
  • General > Validation > 勾选“Suspend all validator”。
  • Window > Customize Perspective > Remove everything you don't use or don't use (try to use shortcut keys), and the same goes for the menu bar (how many times have you used the menu bar's print button?).
  • Install/Update > Automatic Updates > 取消勾选“Automatically find new updates and notify me”。
  • General > Appearance > Uncheck "Enable Animations".
  • Use the default theme. Other themes may slow down.

I've also turned off autosuggestion myself so it doesn't drag me down when typing code. An alternative is to use Ctrl+Space to use manual prompts where needed. It can be done through the following configuration: (Translator's Note: Ctrl+Space? The Chinese will not agree).

  • Java > Editor > Content Assist > Disable "Enable Auto Activation". Remove all unnecessary content in Advanced (not found in Eclipse 4.2.2).

Tip 3: Put the JDK on the RAM Disk

A RAM disk uses the computer's memory as a virtual disk or hard disk. Used to speed up the IO performance of the software in it. A RAM disk created in memory is like a hard disk on a computer. Since this memory is used as a hard disk, other programs cannot use this memory space. We just put the JDK in there, 300MB is enough.

WARNING: DO NOT PERMANENTLY PUT ANY CONTENT TO THE MEMORY DISK, EVERY RESTART, THE CONTENT WILL BE DISAPPEARED AND RE-created.

For Linux users:

There is a detailed description in this link .

For Mac users:

Use the diskutil tool to create a ramdisk

1. Create a new script, for example: ~/tools/batch/ramdisk.sh
replace x, y, z with your JDK version:

1
2
3
#!/bin/bash
diskutil erasevolume HFS+ 'JDK RAMDISK' `hdiutil attach -nomount ram : //614400 `
cp -r /Library/Java/JavaVirtualMachines/jdk1 .x.y_z.jdk /Volumes/JDKRAMDISK

( Note: diskutil expects parameters to be integer multiples of 512 byte sectors: for 300MB it should be 300 * 1024^2 / 512 = 614400)

2. Save the script and change it to executable mode:

1
chmod 755 ~ /tools/batch/ramdisk .sh

Running ramdisk.sh will create the ramdisk:

1
2
3
4
5
6
7
$ ramdisk.sh
Started erase on disk4
Unmounting disk
Erasing
Initialized /dev/rdisk4 as a 300 MB case -insensitive HFS Plus volume
Mounting disk
Finished erase on disk4 JDKRAMDISK

Finder should now discover a new device called JDKRAMDISK, which contains the JDK. Click the "Eject" button to remove the RAM Disk and free up the corresponding memory.

If you want to use this trick, you need this memory disk every time you start Eclipse, otherwise you will see the "A Java Runtime ... must be available in order to run Eclipse" error. The system can be configured to use Automator or an unchtl daemon to ensure that the ramdisk.sh script is automatically executed on every boot.

For Windows users:

1. Download and install a tool called imdisk

2. Create a new batch file, such as: C:/tools/batch/ramdisk.bat
Replace x, y, z with your JDK version number:

1
2
3
4
5
6
7
8
@ echo Placing JDK on Virtual Disk N:/
@ echo off
sc config imdisk start= auto
net start imdisk
imdisk -a -t vm -s 300m -m n:
format n: /q /Y
call xcopy C:<path_jdk>jdk1.x.y_z N:jdk1.x.y_z /S /E /Y /Q
label n: JDK RAMDISK

After running ramdisk.bat, you will see that a new disk N named "JDK RAMDISK" is created, which contains the JDK.

3. Make sure the file is running in administrator mode. Right-click the file, choose Properties - Compatibility - Check "Run this program as an administrator" .

If you want to use this trick, you need this memory disk every time you start Eclipse, otherwise you will see the "A Java Runtime ... must be available in order to run Eclipse" error. The system can be configured to place the ramdisk.bat script in the startup folder.

In order for trick 3 to work, the -vm setting needs to be added to the eclipse.ini file (see the next section for details).

Tip 4: Adjust your eclipse.ini

In Eclipse's optimizations, this is where it gets the most confusing. There are tons of articles on the Internet describing different configuration options. I just introduce my own configuration scheme.

Find your eclipse.ini file:

  • Windows/Linux: at E C L I P S E H O M E translate person Note ECLIPSE_HOME is the path of Eclipse, here it is assumed that Linux is also installed by itself, not through source installation)
  • MacOS: at $ECLIPSE_HOME/Eclipse.app/Contents/MacOS

Understand what the next job entails...

There are two types of properties in eclipse.ini: properties related to Eclipse applications; properties related to the JVM. These options depend on the version of JDK and Eclipse. Below is the latest list I found online .

To understand these properties, it is first necessary to understand the memory layout of the Oracle JVM. Generally speaking, JVM memory is divided into several memory pools, and objects are located in different memory pools according to different existence times.

  • The Eden space (heap) is for many objects just created. The garbage collector typically processes "new generation" objects here on each pass and removes any objects that are no longer in use.
  • Survivor space (heap) contains objects that have not been destroyed in two or three GC passes in Eden space. These objects are still in the young generation, but by moving them to a safer place, the risk of being collected is greatly reduced. The garbage collector runs much less frequently here (the GC judges from past experience that objects here are frequently used).
  • Tenured space (heap) contains objects that live in Survior space for a considerable period of time.
  • The Eternal Generation (non-heap) contains JVM metadata such as class properties, methods, enumerations, etc. Since these data can be shared among multiple JVMs. Therefore, the immortal generation is divided into two areas: read-only and read-write.
  • The code cache (non-heap) provides the memory space for compiling and storing code.

If you're interested, Oracle has an excellent article on configuring garbage collection that details the use of all this space.

In eclipse.ini, the size of each memory pool can be controlled. The configuration below is set for my 16G RAM, but can also be used for 8G RAM.

Use the JDK located in the RAM Disk (use the version number in step 3):

1
-vm /Volumes/JDKRAMDISK/jdk1 .x.y_z.jdk /Contents/Home/
1
-vm N: /jdk1 .x.y_z /bin

Disable bytecode verification (risky)

This skips the validation of class files (see here for information on validation of class files ), meaning that the JVM will not detect the used class files. There is a security risk if the class file used has been modified. Use it at your own risk (I only use it for play, not at work with this option enabled).

Turn on compiler performance optimizations

1
-XX:+AggressiveOpts

Increase the eternal generation space (where new objects are allocated)

1
2
-XX:PermSize=512m
-XX:MaxPermSize=512m

Increase the minimum and maximum heap space (including young and old generation)

1
2
-Xms2048m
-Xmx2048m

Increase heap size for young generation

1
-Xmn512m

Set stack size for each thread

1
-Xss2m

Tune Garbage Collection

1
-XX:+UseParallelOldGC

Finally, here are other options you might see online. Personally, none of these options have a speed-up effect, so it's just for reference. Readers can find the corresponding documentation online to understand and use the corresponding options:

1
2
3
4
5
6
7
8
-XX:MaxGCPauseMillis=10
-XX:+UseG1GC
-XX:CompileThreshold=5
-XX:MaxGCPauseMillis=10
-XX:MaxHeapFreeRatio=70
-XX:+CMSIncrementalPacing
-XX:+UseFastAccessorMethods
-server

Finally, remove all duplicate options, including launcher.XXMaxPermSize, since this option is useless when the XX:MaxPermSize option is enabled.

Tip 5: Turn off antivirus software

If you have antivirus software, make sure they don't check the code folder. Add JDK, Eclipse, your .m2/jar codebase and code folder to your antivirus's whitelist.

Tip 6: Don't run SVN and GIT in Eclipse

This is personal preference. Some people like to combine Eclipse with team collaboration tools. Personally, this is slow, and I'd rather Eclipse focus on development than do many things at once. I also really like the SVN/GIT command line. Anyway, I removed the tools from Eclipse and found it to be much more responsive.

Tip 7: Use the keyboard

One of the nice things about Eclipse is that it contains a lot of keyboard shortcuts. Readers can set relevant shortcut keys by themselves. Usually I reset the debug key so it behaves the same as Visual Studio & Chrome Dev Env. Take the time to learn the shortcut keys. The more shortcut keys you use, the faster your Eclipse experience will be.

The shortcut keys will not be introduced in depth here, and readers can easily find relevant information on the Internet. Here are some must-have shortcut keys:

1
2
3
4
5
6
7
8
9
10
11
Ctrl+Shift+R : jump to resource
Ctrl+Shift+T : jump to class
Ctrl+. : jump to next error
Ctrl+Shift+G : search for references
Ctrl+Shift+P : select matching bracket
Alt+Arrows : go forward / backwards
Ctrl+Space : autocomplete
Ctrl+Shift+F : format source
Ctrl+Shift+O : organize imports
Ctrl+D : delete line
……

That's about it. Without comparing Eclipse with other IDEs, I think Eclipse is a very powerful and fast Java code editing tool.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324524637&siteId=291194637