Common JVM options used with Intellij and what they do
MIT License
Intellij is run on the Java Virtual Machine (VM). The VM has many options/flags that can be used to tune its performance which, by extension, is IntelliJ's performance. This guide can help you get more performance out of your Jetbrains IDE or help you fix problems occuring due to the VMs default configuration. I wrote this guide from the perspective of a person curious about what all these options mean but has no idea what they do.
Don't care about the nitty gritty? Just want to copy and paste a slew of options? Look no further!
This should be a good lowest common denominator set of settings to help increase performance in Intellij.
Replace brackets with values so:
-Xmx[memoryValue]
becomes
-Xmx512m
-server
-ea
-Xmx[memoryValue, If total memory < 2GB then at least 1/4 total memory. If > 2GB then 1-4 GB. (See note below)]
-Xms[memoryValue, at least 1/2 Xmx. Can be = to Xmx]
-XX:+UseG1GC
-XX:ReservedCodeCacheSize=[between 128m and 256m, depending on how much free physical memory you have available]
-XX:+OmitStackTraceInFastThrow
-Dsun.io.useCanonCaches=false
-XX:SoftRefLRUPolicyMSPerMB=50
Note: To tune -Xmx for your project pay attention to the Memory Indicator.
The easiest way to edit these options for your Jetbrains IDE is to use the methods described in this article:
The recommended way of changing the JVM options in the recent product versions is from the Help | Edit Custom VM Options menu. This action will create a copy of the .vmoptions file in the IDE config directory and open an editor where you can change them.
If that method is unavailabe the articles lists out manual ways to edit those files. Read it carefully!
Intellij is run on the Java Virtual Machine (VM). The heap is the memory (in RAM) that is allocated to the java virtual machine. So the heap size is total amount of memory that Intellij can use to operate.
-Xmx[memoryVal] - Specifies the maximum memory allocation of the heap for the VM. This is the maximum amount of memory Intellij can use.
OutOfMemoryError
errors from Intellij you should increase this value.-Xms[memoryVal] - Specifies the initial memory allocation of the heap for the VM. This will be the amount of memory Intellij starts with.
The garbage collector (GC) is a program in the VM that removes unused objects/resources and frees up space on the heap.
From the garbage collector's perspective there are two main sections, called generations, inside the heap:
Garbage collection is done on both generations, but each has different consequences.
Controlling the size of the young generation is an important tuning tool:
If the young generation is too small, short-lived objects will quickly be moved into the old generation where they are harder to collect. Conversely, if the young generation is too large, we will have lots of unnecessary copying for long-lived objects that will later be moved to the old generation anyway.
So choosing the right size depends on how you use Intellij. If you are constantly opening new files and jumping around projects you may want a larger young generation so that objects aren't being moved to the old generation quickly. If you are mostly static in your usage (staying in one area of a project or working on small scopes) a smaller young generation may be better for you as you won't be pushing new objects into the heap as often.
There are two ways to manage the young generation:
-XX:NewRatio=[ratio] - Specifies the young generation size in relation to the size of the old generation.
-Xmn[memoryVal] - Specifies the memory allocated to the young generation.
(IMO) There are two main GC approaches that can be used.
Note: If your heap is larger than 4GB it is recommended to use G1
This option uses mutliple threads to attempt to do GC in the background as to avoid application stopping. If you experience Intellij becoming jerky/unresponsive during heavy usage this may alleviate those problem.
Introduced in JDK 7 Update 4 G1 is similar to CMS but is built to support large heaps (4GB and larger). It breaks up the generations into smaller regions and keeps tracks of regions that produce more garbage. This is supposed to prevent large "stop the world" GC events that can occur in large heaps.
-XX:ParallelGCThreads=[value] - Specifies the number of GC thread to use for parallel GC (ParNewGC)
-XX:SurvivorRatio=[ratio] - Specifies the size of survivor generations inside the young generation.
-XX:SoftRefLRUPolicyMSPerMB=[value] - Specifies the number of milliseceonds, per free MB in the heap, a soft reference should remain alive.
-Xss=[memoryValue] - Specifies the memory allocated to a new stack
-XX:PermSize=[memoryValue] and -XX:MaxPermSize=[memoryValue]
Java.lang.OutOfMemoryError: PermGen space
events in Intellij often you can increase this value. Recommend 512m and increase from their until the errors disappear.-XX:ReservedCodeCacheSize=[memoryValue] - Used to store the native code generated for compiled methods..
-XX:+OmitStackTraceInFastThrow - This is a flag recommended by Jetbrain. A description of what this flag does can be found here.
-XX:+HeapDumpOnOutOfMemoryError - Will cause a dump of the heap when an OutOfMemoryError
error occurs (as explained here).
OutOfMemoryError
errors often.-XX:MaxJavaStackTraceDepth=[integer] - This specifies how many entries a stack trace for a thrown error or exception can have before a StackOverflowError
is thrown.
StackOverflowError
.-ea - This option enables assertions.
AssertionError
. There is no performance overhead with this option if you are not using assertions (or not coding in Java).-Dsun.io.useCanonCaches=[boolean] - Specifies whether canonical file paths are cached.
-XX:+AggressiveOpts - Turns on some peformance optimizations that are expected to be on by default in upcoming releases.
-Djava.net.preferIPv4Stack=[boolean] - Specifies whether Intellij should prefer using IPv4 connections.
-Djava.net.preferIPv6Addresses=true
Please feel free to make a PR to add/modify any options. I'm still learning about this stuff myself