Search code examples
javaperformancejvm-arguments

Speed tradeoff of Java's -Xms and -Xmx options


Given these two commands

A:

$ java -Xms10G -Xmx10G myjavacode input.txt

B:

$ java -Xms5G -Xmx5G myjavacode input.txt

I have two questions:

  1. Since command A reserves more memory with its parameters, will A run faster than B?
  2. How do -Xmx and -Xms affect the running process and the output of my program?

Solution

  • It depends on the GC your java is using. Parallel GCs might work better on larger memory settings - I'm no expert on that though.

    In general, if you have larger memory the less frequent it needs to be GC-ed - there is lots of room for garbage. However, when it comes to a GC, the GC has to work on more memory - which in turn might be slower.