• Stars
    star
    748
  • Rank 60,661 (Top 2 %)
  • Language
  • License
    MIT License
  • Created about 8 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Common JVM options used with Intellij and what they do

Intellij Jvm Options Explained

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.

TL;DR

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.

  • If you have free memory increase -Xmx until Memory Indicator usage is < 85%.
  • If you are memory constrained and can't reach that target -Xmx should be at least 1/2 to 3/4 total physical memory.

How to Edit VM Options

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!

VM Options, Explained!

Heap on the VM

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.

  • If you are frequently recieving OutOfMemoryError errors from Intellij you should increase this value.
  • Increasing this value should also speed up processes like inspection time for large files as Intellij will have to do less swapping of memory to stay inside the limit (?)

-Xms[memoryVal] - Specifies the initial memory allocation of the heap for the VM. This will be the amount of memory Intellij starts with.

  • Increasing this value should make Intellij start up faster as it will have a larger pool initially and so will not have to wait to allocate more memory as it spins up.

Garbage Collection

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:

  • Young Generation - New objects are created in the young generation.
  • Old Generation - Objects that are "live" and have survived a few GC (garbage collections) get moved to the old generation, as well as any objects too big for the young generation.

Garbage collection is done on both generations, but each has different consequences.

  • GC on the young generation is "little". Most objects "die" in the young generation, never to be used again. So collection on this generation is considered minor in terms of impact on the VM.
  • GC on the old generation is considered "full GC" and has a much larger impact on the VM as it collects across the entire heap. GC here only happens when there is not enough memory on the heap to allocate new objects.

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.

  • The potential advantage of this approach is that the young generation will grow and shrink automatically when the JVM dynamically adjusts the total heap size at run time.
  • Use this if the projects you work with vary drastically in their memory usage.
  • I recommend a ratio between 2 and 4. This means the young generation will be 1/3 or 1/4 the size of the old generation.

-Xmn[memoryVal] - Specifies the memory allocated to the young generation.

  • This flag is equivalent to -XX:NewSize and -XX:MaxNewSize, setting the same value for both.
  • The only advantage this has compared to NewRatio is it allows more granular control of the young generation size.

GC Algorithm

(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

CMS

  • -XX:+UseConcMarkSweepGC

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.

G1

  • -XX:+UseG1GC

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.

Other GC Flags

-XX:ParallelGCThreads=[value] - Specifies the number of GC thread to use for parallel GC (ParNewGC)

  • If not explicitly set this flag, the JVM will use a default value which is computed based on the number of available (virtual) processors. This is what you normally want to do (not set it).
  • Useful if you have more than one JVM running and you want to reduce resource use.

-XX:SurvivorRatio=[ratio] - Specifies the size of survivor generations inside the young generation.

  • A survivor generation holds all of the objects still "live" after a GC on the young generation but not yet passed to the old generation.
  • Normally not a huge factor in performance.
  • Most values I see are between 8 and 6.

-XX:SoftRefLRUPolicyMSPerMB=[value] - Specifies the number of milliseceonds, per free MB in the heap, a soft reference should remain alive.

  • The default value is 1000. Jetbrains recommends this value be set to 50.
  • Honestly I don't know how this helps. My speculation is that many objects in Intellij fall into a "use once" use case so decreasing this value means they are cleaned up faster.

Everything Else

-Xss=[memoryValue] - Specifies the memory allocated to a new stack

  • Every thread created in the VM gets its own stack space. This is space used to store local variables and references.
  • Generally does not need to modified. However a smaller stack size will use less memory.

-XX:PermSize=[memoryValue] and -XX:MaxPermSize=[memoryValue]

  • These refer to the perm size which is the memory used by the VM for data outside of your application, just for the VM.
  • Normally does not need to be adjusted but if you are seeing Java.lang.OutOfMemoryError: PermGen space events in Intellij often you can increase this value. Recommend 512m and increase from their until the errors disappear.

-server - In a nutshell it tells the JVM to spend more time on the optimization of the fragments of codes that are most often used (hotspots). It leads to better performance at the price of a higher overhead at startup.

-XX:ReservedCodeCacheSize=[memoryValue] - Used to store the native code generated for compiled methods..

  • Jetbrains recommends 240m for this value.

-XX:+OmitStackTraceInFastThrow - This is a flag recommended by Jetbrain. A description of what this flag does can be found here.

  • Essentially Intellij may check for certain built-in exceptions thrown in the VM -- or they may be thrown by misbehaving plugins -- and producing stack traces for an exception requires a lot of overhead. Using this option prevents stack traces from being generated for these exceptions and may therefore reduce jitteriness caused by resources being used for this purpose when the exceptions are insignificant.
  • There is insignificant overhead associated with using this option so it is recommended to use it unless you want to debug Intellij itself or a misbehaving plugin.

-XX:+HeapDumpOnOutOfMemoryError - Will cause a dump of the heap when an OutOfMemoryError error occurs (as explained here).

  • There is no overhead for using this option so it may be used by default however it is not necessary unless you are experiencing 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.

  • The JVM has a default of 1024 entries before throwing StackOverflowError.
  • If you are dealing with huge stack traces you can use this option to increase the allowed entriers before overflow.

-ea - This option enables assertions.

  • If you are debugging Intellij or a plugin for it you need to use this option in order to have any assertions throw 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.

  • By default java caches filenames for 30 seconds.
  • Jetbrains recommend setting the value of this option to false. I'm guessing this is because IntelliJ frequently deals with file paths/names and frequent changes can cause a performance hit when these properties change and the filenames are still cached.

-XX:+AggressiveOpts - Turns on some peformance optimizations that are expected to be on by default in upcoming releases.

  • These are minor changes and will not affect the rest of your configuration. Not a necessary flag but may see some performance improvements.
  • Keep in mind the changes this flag turns on change for each java release so make sure to re-evaluate when/if Intellij changes the version of Java packaged with Intellij!

-Djava.net.preferIPv4Stack=[boolean] - Specifies whether Intellij should prefer using IPv4 connections.

  • If you are experiencing connectivity issues when running Intellij under Java 1.7 Jetbrains recommends setting this flag to true.
  • Alternatively if your environment only accepts IPv6 connections use the flag -Djava.net.preferIPv6Addresses=true

Contributing

Please feel free to make a PR to add/modify any options. I'm still learning about this stuff myself

More Repositories

1

multi-scrobbler

Scrobble plays from multiple sources to multiple clients
TypeScript
334
star
2

laravel-elasticbeanstalk-cron

Ensure one instance within an EB environment is running Laravel's Scheduler
PHP
60
star
3

laravel-elasticbeanstalk-queue-worker

Shell
51
star
4

context-mod

an event-based, reddit moderation bot built on top of snoowrap and written in typescript
TypeScript
49
star
5

tautulli-notification-digest

Consolidate Tautuilli Notification agent events for discord
TypeScript
15
star
6

rtl-sdr-icecast-docker

Relay HD radio through icecast and save to mp3
Python
10
star
7

espanso-all-emojis

All emojis from gemoji, with non-conflicting alt names, as an espanso package
8
star
8

emojify

Converts Discord emoji shortcodes back to universal emojis (unicode)
JavaScript
4
star
9

logging

A typed, opinionated, batteries-included, Pino-based logging solution for backend TS/JS projects
TypeScript
4
star
10

react-cowsay

A react wrapper for cowsay
JavaScript
4
star
11

string-sameness

Compare the sameness of two strings
TypeScript
4
star
12

interview-questions

PHP
3
star
13

szurubooru-ocr

OCR text extraction for szurubooru
TypeScript
3
star
14

redditdatalive

Live Reddit Data, visualized
JavaScript
2
star
15

sendmail-ses-elasticbeanstalk

Automate sendmail configuration with AWS SES on AWS Elastic Beanstalk deployments
Shell
2
star
16

linuxsetup

Resources for setting up my personal linux environment
JavaScript
2
star
17

unraid-docker-templates

Templates for dockers on unraid
2
star
18

awesome-data-mining

Data sets, mining and scraping tools, and resources for gathering that sweet sweet information
2
star
19

endlessh-notify

Event notification for endlessh and endlessh-go
TypeScript
1
star
20

doyouremember

A silly tribute to a catchy tune
HTML
1
star
21

laravel-loggly

A service provider for logging with Loggly
PHP
1
star
22

ts-project-base

TypeScript
1
star
23

laravel-mail-extras

PHP
1
star
24

streamSave

Save streaming audio locally using pure JS
JavaScript
1
star
25

themobilesocial.com

HTML
1
star
26

annals-of-awesome

Awesome projects and best practices I want to use in my work
1
star
27

cm-yaml

TypeScript
1
star
28

winston-duplex

A simple duplex (transform) stream transport for winstonjs to enable streaming/event listeners
TypeScript
1
star
29

pushshift-sandbox

a sandbox for pushshift.io queries
JavaScript
1
star
30

react-interpunct

React component to visibly display whitespace characters
JavaScript
1
star
31

EasyClockKiller

A simple script for automating clocking in and out of easyclock.net
JavaScript
1
star
32

swag-dashboard-archived-logs

Make SWAG Dashboard read ALL logs
Shell
1
star
33

endlessh-go-crowdsec

1
star
34

regex-buddy-core

Javascript helper functions for handling Regular Expressions and parsing user input as Regular Expressions
TypeScript
1
star
35

discoFoxx

A sly, simple discord bot written for extensibility
TypeScript
1
star
36

blog

Makefile
1
star
37

discord-overseer-info

TypeScript
1
star
38

get-version

Get a version identifier from set a ordered sources
TypeScript
1
star