IntelliJ idea Memory Optimization best practices

Source: Internet
Author: User
Tags xms intel core i7

"Editor's note" the author, in a discussion with colleagues, found that using different setup schemes for IntelliJ idea memory would have different effects on the IDE's speed and responsiveness.

Don ' t be a Scrooge and give your ides some more memory

Don't be a miser, save the IDE a little more memory.

Yesterday, we discussed whether to customize the memory settings of IntelliJ idea, some people choose the default settings, some people will make simple changes to the default settings, and some developers will be based on their needs to make a comprehensive and complex settings. The author's current work is to deal with several micro-service projects and an old project, while the customer's core business needs are very large. After a simple setup of IntelliJ idea memory, I obviously felt the IDE's improved speed and responsiveness. But I did not carry out specific measurements at the time, so this is only a subjective feeling.

However, one of the developers involved in the discussion sent the author a copy of his settings, which are extremely complex, even for the same project. I am not dissatisfied with my own settings, but very curious, these completely different settings compared to the default settings provided by JetBrains, will be how different.

Goal

The author's plan is to test the effects of each setting in a scenario that is close to a daily development project (load a large project, load 2, 3 microservices, Git pull), and choose the best setting when memory consumption and speed are optimal.

Test Machines and projects
    • Laptops: MacBook Pro Retina, 2.3GHz Intel Core i7, 16GB 1600Mhz ddr3,ssd Disc, OS X Yosemite

Project

    • Major item--monolith, 700,000 lines of code (Java 8 and Groovy), 303 gradle Modules

    • Two microservices-small projects with about 10000--20000 lines (Java 8 and Groovy), each with a gradle module

Test scenario
    1. Close all items in idea
    2. Setup based on the test file idea.vmoptions
    3. Restart your computer
    4. Close all unrelated items (communicators, etc.) after startup
    5. Open idea (test time)
    6. Open large item (test time)
    7. Check Jstat-gcutil
    8. Open two micro-service items (test time)
    9. Check Jstat-gcutil
    10. Go back to the big item and click on the "Refresh Gradle Project" button (test time)
    11. Check Jstat-gcutil
Jstat-gcutil

The Jstat is a tool that comes with the JDK, using the JVM's built-in instructions for real-time command-line monitoring of Java application resources and performance, as well as monitoring the Heap size and garbage collection status. It has a number of options to collect various data (complete documents), but this is only used:-gcutil:

-gcutil-summaryof garbage collection statistics. S0:survivorSpace0 utilizationAs a percentageOfTheSpace ' s current capacity. S1:survivorSpace1 utilizationAs a percentageOfTheSpace ' s current capacity. E:edenSpace utilizationAs a percentageOfTheSpace ' s current capacity. O:oldspace utilization As a percentage of the   space ' s current capacity. M:metaspace utilization as a percentage of the   space ' s current capacity. Ccs:compressed class space utilization as a percentage. Ygc:number of young generation GC events. Ygct:young Generation garbage collection time . Fgc:number of full GC events. Fgct:full garbage collection Time . Gct:total garbage collection Time .              

The output of this command is as follows:

S0     S1    E     O     M    CCS  YGC YGCT FGC  FGCT   GCT89.70 0.00 81.26 74.27 95.68 91.76 40 2.444 14 0.715 3.159

In this article, the most important parameters are the number of GC events (YGC and FGC) and the collection time (YGCT and FGCT).

Test settings

The author set up four different settings, in order to remember, give them a different name.

Default (Gray identification)

Default settings provided by JetBrains:

-Xms128m-Xmx750m-XX:MaxPermSize=350m-XX:ReservedCodeCacheSize=240m-XX:+UseCompressedOops

Big (Large) (Red logo)

To Xmx with 4096MB, Reservedcodecachesize set 1024MB, which is already quite a lot of memory:

-Xms1024m-Xmx4096m-XX:ReservedCodeCacheSize=1024m-XX:+UseCompressedOops

Balanced (balanced) (Blue logo)

XMX and Xms are allocated 2GB, which is fairly balanced memory consumption:

-Xms2g-Xmx2g-XX:ReservedCodeCacheSize=1024m-XX:+UseCompressedOops
Sophisticated (complex) (Orange logo)

As above, both XMX and Xms allocate 2GB, but specify different garbage collector and many different flags for GC and memory management:

-server-xms2g-xmx2g-Xx: newratio=3-xss16m-Xx: +useconcmarksweepgc-Xx: +cmsparallelremarkenabled-Xx: concgcthreads=4-Xx:reservedcodecachesize=240m-xx:+alwayspretouch-XX :+tieredcompilation-XX :+usecompressedoops-XX :softreflrupolicymspermb=50-dsun.io.usecanoncaches=false- djava.net.preferipv4stack=true-djsse.enablesniextension=false-ea    

The above is the author's test settings, in order to execute the test case, also need to create a idea.vmoptions file under ~/library/preferences/intellijidea15/(this is the MAC OS system path settings, view this article, Set up based on your operating system)

Now, execute the test case and compare the results.

Result idea Start time

As shown, the startup time is not dependent on the memory setting. IDEA has a test time of 10 seconds in all scenarios, regardless of memory allocation. This is not surprising, because at this early stage, these settings do not affect the behavior of the app.

The time it takes to load a large project

Now load the Monolith project and its 700,000 lines of code.
Finally, there are some differences. The default setting takes almost 3 times times as much time as the other. It is clear that such a large code base requires more memory. If we do:

<IDEA_PID>

Will find that, compared to other settings, the GC will become unusually busy by default settings.

Not only is the GC's total time to release memory very high (almost 50 times times), but the average execution time of the full GC is also very long. A large amount of time is spent on full GC, which is the main reason why the IDE is slow to respond.

Open two micro services in idea

Now load these two microservices projects, open in idea and compare the time they consume.

Under this test case, the differences are very obvious, the complex settings perform best, and the default settings are still lost to the other two settings.

Use Jstat–gcutil again

After loading two microservices, check the performance of the GC when you open 3 items at the same time. The test found that 3 different custom settings performed almost the same, and the default settings were simply too weak to explode.

The last race: Reload Monolith

Now, I need to get the latest version of the Monolith project from the repository and refresh the Gradle module so that idea can see all the new classes.

Important: The gray bar bars representing the default settings are very high because idea crashes during the refresh process and the author cannot measure the actual time. Obviously, the default allocated memory is not sufficient to perform this operation.

However, from the three custom examples, it can be found that large memory configuration takes the shortest time. So, memory allocation still plays a role.

Last time using Jstat-gcutil

Because idea cannot refresh the project by default, the default setting for this test is not included.

As you can see, the difference between the three is small, but the full GC executes the fastest in the Big configuration. In addition, XMX memory is significantly more helpful for responsiveness improvements.

Summarize

In this brief experiment, you can see that even fine-tuning IntelliJ idea memory can greatly improve IDE performance. Of course, the more memory allocation, the better the performance. However, you will also find that many other applications outside the IDE also need to consume memory, so the goal should be to find a balance between increased performance and memory consumption. The author believes that in most cases, setting the XMX value between 2G and 3G is the best. If you have more time, you can use Jstat and jvisualm to check how the different JVM settings affect performance and memory consumption.

Discuss

How is your idea.vmoptions configured? Do you have any other ways to improve Intelij idea performance? Talk about it together.

(Compiled from: Https://dzone.com/articles/the-one-and-only-reason-to-customize-intellij-idea)

http://blog.csdn.net/github_32521685/article/details/50541436

IntelliJ idea Memory Optimization best practices

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.