jrbudda / Vivecraft_116

VR mod for Minecraft. For Version 1.16.X http://www.vivecraft.org
Other
188 stars 49 forks source link

Default JVM options introduce pretty frequent periodic GC freeze #103

Closed matejdro closed 2 years ago

matejdro commented 3 years ago

With default Vivecraft 1.16.5 installation, Vivecraft seems to add bunch of GC-related flags into launcher's JVM options entry.

When playing with those default flags it seems like JVM is performing GC way too aggressively - Game has 8GB of RAM allocated, but it will never even use it past the 1GB since GC keeps very aggressively pruning it.

This causes frame drop every couple of seconds when game freezes momentarily due to GC.

Manually editing launcher entry and removing all flags but the Xmx flag (that gives the game more memory) fixes the issue.

Techjar commented 3 years ago

You sure the args you had were put there by the Vivecraft installer? We use ParallelGC tuned for low pause times by default which works well for this application, and does not exhibit the behavior you describe (there's still a couple missed frames periodically, but not an obvious freeze, and I've definitely seen it use more than 1GB).

Also, there is absolutely no reason to give vanilla Minecraft 8GB of memory unless you're running a stupid high render distance or something.

matejdro commented 3 years ago

Here is fpsVR chart with extra GC flags that Vivecraft adds:

-Xmx8G -Xms8G -XX:+UseParallelGC -XX:ParallelGCThreads=3 -XX:MaxGCPauseMillis=3 -Xmn256M

image

Note the right chart. Every couple of seconds there is a huge spike like this where a single frame takes 27+ms to render.

When I delete all flags but the Xmx, this spike disappears:

-Xmx8G

image

Also, there is absolutely no reason to give vanilla Minecraft 8GB of memory unless you're running a stupid high render distance or something.

Probably not, but free memory is a wasted memory so if I have bigger amounts of memory in my PC, I might as well use it.

This is with HP Reverb G2, running at 50% render scale, amounting to around 2160x2160 visible area.

Techjar commented 3 years ago

That spike looks entirely nominal, and in my testing the default GC parameters on Java 8 are worse as they cause less frequent but particularly long pauses, which is frankly more annoying. Are you using something other than the JVM bundled with the Minecraft launcher?

matejdro commented 3 years ago

I'm running

java version "1.8.0_291"
Java(TM) SE Runtime Environment (build 1.8.0_291-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.291-b10, mixed mode)

Located in the C:\Program Files (x86)\Minecraft Launcher\runtime\jre-legacy\windows-x64\jre-legacy\bin. So I guess this is the bundled java.

Techjar commented 3 years ago

That's weird, I don't recall Mojang updating the JVM. It's always been 1.8.0_51. Well, whatever, 1.17 is using Java 16 so we'll be making ZGC the default there which just solves all these problems. Like I said, the default GC parameters collect at longer intervals, which gets rid of the almost rythmatic stuttering but instead causes longer freezes. The period depends on how much memory you allocate, but just throwing more memory at the problem is not a solution; ZGC is.

You can use ZGC now if you install Java 14 or newer separately and point the launcher installation it. Our installer even includes a nice convenient checkbox to set the right JVM arguments, and prompts you to select the correct Java 14+ executable if it hasn't been selected before for that particular installation. I highly recommend it, really does make the game run noticeably smoother.