This article is too hardcore and is recommended for those with Java experience.

1. The introduction

I believe that students who do Java development should not be unfamiliar with IDEA, even if they do not use IDEA to do development, then they should not be unfamiliar with Eclipse. If you do not use either of these two tools, I would like to ask a question: are you using Notepad?

In addition to the notepad, I believe that all the students are impressed by the opening speed of IDEA or Eclipse.

As long as you haven’t changed the boot parameters yourself, no matter how high the computer is configured, I’m sure it won’t turn on any faster.

I have written so many articles about the JVM, today I will try to optimize the startup speed of IDEA (I don’t have Eclipse at hand), this is a small test, I hope not to overturn the car in the end.

2. Start

I used VisualVM, which comes with the JDK, and mainly used its GC plug-in.

First, open IDEA for the first time, and the loading time will be manually blocked according to the loading of all components of IDEA (originally I wanted to find a plug-in, but the plug-in for IDEA was not found).

IDEA in the process of opening, there will be a progress bar in the lower right corner to read the bar, I will roughly wait for that to read the time.

In the process of subsequent operation, I found that it was not necessary, because the gap was too obvious.

Open IDEA for the first time with the default configuration, and then look at the VisualVM data graph:

GC:

Overview:

I was shocked by the speed of the Class Loader. It took 3m 34s to load, but since all the other operations were in parallel, this item took a lot of time.

The Minor GC occurred 147 times, but the Full GC did not occur once, taking a total of 712ms.

But look at the overview below and you can see that the current heap size is constantly increasing.

Select * from D:\Program Files\JetBrains\apps\IDEA -u \ch-0; select * from D:\Program Files\JetBrains\apps\IDEA -u \ch-0; When found, open the idea64.exe.vmoptions file:

-Xms128m
-Xmx750m
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-ea
-XX:CICompilerCount=2
-Dsun.io.useCanonPrefixCache=false
-Djdk.http.auth.tunneling.disabledSchemes=""
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow
-Djdk.attach.allowAttachSelf=true
-Dkotlinx.coroutines.debug=off
-Djdk.module.illegalAccess.silent=true
Copy the code

You can see that the minimum heap is set to 128MB, and the maximum heap is 750MB, using CMS collector, I use computer hardware memory is 16GB, so large memory space, directly change the minimum heap to 1G, the maximum heap to 2G, shut down the IDEA and restart to see the effect.

The modified configuration is as follows:

-Xms1g
-Xmx2g
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
Copy the code

GC:

Overview:

The Class Loader time is reduced from 3m to 24s, and the Minor GC time is reduced by half from 712ms to 342ms, and the number of times is reduced from 147 to 9. There is still no Full GC generated.

And when you look at the overview diagram, you can see that the heap memory expansion was only expanded once.

Can you make it shorter? -xverify: None :none :none :none :none :none :none :none :none

The modified configuration is as follows:

-Xms1g
-Xmx2g
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-Xverify:none
Copy the code

GC:

Overview:

Sure enough, the load time continued to drop from 24s to 19s, a reduction of about a quarter.

Then I wondered if the minimum heap size was set to 2G, so the heap size did not need to be expanded, would it have a more positive impact?

The modified configuration is as follows:

-Xms2g
-Xmx2g
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-Xverify:none
Copy the code

GC:

Overview:

It didn’t really work out very well.

As you can see from the overview, my current version of IDEA uses the built-in JDK11:

There is a G1 collector in JDK11, I can either turn on G1 and try it:

-Xms1g
-Xmx2g
-XX:ReservedCodeCacheSize=240m
-XX:+UseG1GC
-XX:SoftRefLRUPolicyMSPerMB=50
-Xverify:none
Copy the code

GC:

Overview:

It looks like Minor’s GC time went up slightly, and the number of GCS went from 9 to 19.

But see the overview diagram found a more magical things, when using the G1, the use of heap size did not break through the 1 g, it seems more computer memory is not big enough classmates recommended G1 collector, although time consuming of GC increases slightly, but can reduce the use of memory, and the GC mechanism of G1 is a large number of parallel, It doesn’t matter at all.

Finally, I put in my modified overall configuration:

-Xms1g
-Xmx2g
-XX:ReservedCodeCacheSize=240m
-XX:+UseG1GC
-XX:SoftRefLRUPolicyMSPerMB=50
-Xverify:none
-ea
-XX:CICompilerCount=2
-Dsun.io.useCanonPrefixCache=false
-Djdk.http.auth.tunneling.disabledSchemes=""
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow
-Dkotlinx.coroutines.debug=off
-Djdk.module.illegalAccess.silent=true
-Dide.no.platform.update=true
-Djdk.attach.allowAttachSelf=true
Copy the code

Of course, if you don’t use IDEA, you can also use the Jetbrain family bucket kit, such as Pycharm, which is most commonly used in Python. I also modified the configuration for Pycharm, and the startup speed is definitely increased, which is visible to the eye.


The article continues to be updated. You can search “geek excavator” on wechat for the first time to read, reply to the keywords I prepared various tutorials, welcome to read.