僵尸毁灭工程吧 关注:131,740贴子:1,078,976
  • 23回复贴,共1

【性能优化】使用jre21、ZGC、ZGenerational可带来更进一步提升

只看楼主收藏回复

不清楚ZGC和ZGenerational自行百度下。
虽然游戏字节码是jdk17版本的,但其实jre21是能向后兼容旧的17版本字节码文件并启用新运行特性的,目前只有21以上版本可使用ZGenerational
教程如下


IP属地:广东1楼2024-10-31 02:23回复
    2L相关链接


    IP属地:广东2楼2024-10-31 02:24
    收起回复
      1、下载jre21后,解压到游戏目录,要求最终目录结构如下


      IP属地:广东3楼2024-10-31 02:28
      收起回复
        2、修改游戏目录下的ProjectZomboid64.bat文件,修改SET PZ_CLASSPATH=之后的值为
        commons-compress-1.18.jar;istack-commons-runtime.jar;jassimp.jar;javacord-2.0.17-shaded.jar;javax.activation-api.jar;jaxb-api.jar;jaxb-runtime.jar;lwjgl.jar;lwjgl-natives-windows.jar;lwjgl-glfw.jar;lwjgl-glfw-natives-windows.jar;lwjgl-jemalloc.jar;lwjgl-jemalloc-natives-windows.jar;lwjgl-opengl.jar;lwjgl-opengl-natives-windows.jar;lwjgl_util.jar;sqlite-jdbc-3.27.2.1.jar;trove-3.0.3.jar;uncommons-maths-1.2.3.jar;./
        ".\java21\bin\java.exe" -Djava.awt.headless=true -Dzomboid.steam=1 -Dzomboid.znetlog=1 -XX:-CreateCoredumpOnCrash -XX:-OmitStackTraceInFastThrow -XX:+UseZGC -XX:+ZGenerational -Xmx8192m -Xlog:gc* -Djava.library.path=./win64/;./ -cp %PZ_CLASSPATH% zombie.gameStates.MainScreenState %1 %2
        IF %ERRORLEVEL% NEQ 0 (
        ".\java21\bin\java.exe" -Djava.awt.headless=true -Dzomboid.steam=1 -Dzomboid.znetlog=1 -XX:-CreateCoredumpOnCrash -XX:-OmitStackTraceInFastThrow -XX:+UseZGC -XX:+ZGenerational -Xmx8192m -Xlog:gc* -Djava.library.path=./win64/;./ -cp %PZ_CLASSPATH% zombie.gameStates.MainScreenState %1 %2
        )
        PAUSE
        内容如图


        IP属地:广东5楼2024-10-31 02:33
        收起回复
          3、修改ProjectZomboid64.json文件内容如下
          {
          "mainClass": "zombie/gameStates/MainScreenState",
          "classpath": [
          ".",
          "commons-compress-1.18.jar",
          "istack-commons-runtime.jar",
          "jassimp.jar",
          "javacord-2.0.17-shaded.jar",
          "javax.activation-api.jar",
          "jaxb-api.jar",
          "jaxb-runtime.jar",
          "lwjgl.jar",
          "lwjgl-natives-windows.jar",
          "lwjgl-glfw.jar",
          "lwjgl-glfw-natives-windows.jar",
          "lwjgl-jemalloc.jar",
          "lwjgl-jemalloc-natives-windows.jar",
          "lwjgl-opengl.jar",
          "lwjgl-opengl-natives-windows.jar",
          "lwjgl_util.jar",
          "sqlite-jdbc-3.27.2.1.jar",
          "trove-3.0.3.jar",
          "uncommons-maths-1.2.3.jar"
          ],
          "vmArgs": [
          "-Djava.awt.headless=true",
          "-Xmx8192m",
          "-Dzomboid.steam=1",
          "-Dzomboid.znetlog=1",
          "-Djava.library.path=win64/;.",
          "-XX:-CreateCoredumpOnCrash",
          "-XX:-OmitStackTraceInFastThrow",
          "-XX:+UseZGC"
          ],
          "windows": {
          "6.1": {
          "vmArgs": [
          "-XX:+UseZGC",
          "-Xmx8192m"
          ]
          },
          "10.0.17134": {
          "vmArgs": [
          "-XX:+UseZGC",
          "-Xmx8192m"
          ]
          }
          }
          }


          IP属地:广东6楼2024-10-31 02:34
          收起回复
            4、之后运行游戏请手动打开ProjectZomboid64.bat这个文件即可


            IP属地:广东7楼2024-10-31 02:39
            回复
              5、那么如何确定启用了ZGC和ZGenerational?
              打开ProjectZomboid64.bat之后我们会看到很多输出代码,ctrl+A然后ctrl+c去复制这些输出代码到记事本(注意,不要等满屏很久再复制,前面的会被刷没),我们会看到类似这样的输出
              [0.003s][info][gc,init] Initializing The Z Garbage Collector
              [0.003s][info][gc,init] Version: 21.0.5+11-LTS (release)
              [0.004s][info][gc,init] NUMA Support: Disabled
              [0.004s][info][gc,init] CPUs: 32 total, 32 available
              [0.004s][info][gc,init] Memory: 32543M
              [0.004s][info][gc,init] Large Page Support: Disabled
              [0.004s][info][gc,init] Address Space Type: Contiguous/Unrestricted/Complete
              [0.004s][info][gc,init] Address Space Size: 131072M
              [0.005s][info][gc,init] Min Capacity: 8M
              [0.005s][info][gc,init] Initial Capacity: 510M
              [0.005s][info][gc,init] Max Capacity: 8192M
              [0.005s][info][gc,init] Soft Max Capacity: 8192M
              [0.005s][info][gc,init] Medium Page Size: 32M
              [0.005s][info][gc,init] Pre-touch: Disabled
              [0.005s][info][gc,init] Uncommit: Enabled
              [0.006s][info][gc,init] Uncommit Delay: 300s
              [0.007s][info][gc,init] GC Workers for Old Generation: 8 (dynamic)
              [0.008s][info][gc,init] GC Workers for Young Generation: 8 (dynamic)
              [0.016s][info][gc,init] GC Workers Max: 8 (dynamic)
              [0.016s][info][gc,init] Runtime Workers: 20
              [0.016s][info][gc ] Using The Z Garbage Collector
              其中Using The Z Garbage Collector代码已经启用ZGC
              而以下输出代表成功启用ZGenerational
              [0.007s][info][gc,init] GC Workers for Old Generation: 8 (dynamic)
              [0.008s][info][gc,init] GC Workers for Young Generation: 8 (dynamic)


              IP属地:广东8楼2024-10-31 02:39
              收起回复
                6、为什么要用ZGenerational?看以下延迟图就知道了,横坐标是负载(打比方是mod数量),纵坐标是延迟(低延迟则代表更流畅),三条横线中G1代表G1GC GenZGC代表启用ZGenerational的ZGC,我们看到普通ZGC在低负载的时候,延迟比G1低,但是负载高了反而不如G1GC,而启用ZGenerational的ZGC无论在任何条件下延迟都低于G1GC


                IP属地:广东9楼2024-10-31 02:46
                回复
                  ZGC requires Windows version 1803 or later
                  Win7 用户无福消受,看来就G1凑合凑合吧~


                  IP属地:上海10楼2024-10-31 06:03
                  回复
                    不知道linux可以用不,steamdeck玩是真的舒服


                    IP属地:吉林来自Android客户端11楼2024-11-01 01:33
                    收起回复
                      我之前换过,但是发现了一个奇怪的情况:修改json和bat后,通过exe启动游戏,实际上没用到分代ZGC,我在jconsole里看还是在用G1GC;但是如果走bat启动那就能看到分代情况了。


                      IP属地:江苏12楼2024-11-01 17:04
                      收起回复
                        b42好像没用了


                        IP属地:江西来自Android客户端13楼2024-12-30 23:15
                        回复
                          B42有类似方法吗


                          IP属地:中国香港14楼2024-12-31 14:53
                          回复