diff --git a/paper-server/patches/sources/net/minecraft/server/MinecraftServer.java.patch b/paper-server/patches/sources/net/minecraft/server/MinecraftServer.java.patch index 67119dfc8..f060f380b 100644 --- a/paper-server/patches/sources/net/minecraft/server/MinecraftServer.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/MinecraftServer.java.patch @@ -719,7 +719,7 @@ + } catch (java.lang.InterruptedException ignored) {} // Paper + if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) { + MinecraftServer.LOGGER.info("Saving usercache.json"); -+ this.getProfileCache().save(); ++ this.getProfileCache().save(false); // Paper - Perf: Async GameProfileCache saving + } + // Spigot end diff --git a/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch b/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch index 9cfcf2767..454eb6341 100644 --- a/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch @@ -170,7 +170,7 @@ DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode); InetAddress inetaddress = null; -@@ -156,10 +246,23 @@ +@@ -156,21 +246,34 @@ return false; } @@ -195,7 +195,11 @@ DedicatedServer.LOGGER.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file."); } -@@ -170,7 +273,7 @@ + if (this.convertOldUsers()) { +- this.getProfileCache().save(); ++ this.getProfileCache().save(false); // Paper - Perf: Async GameProfileCache saving + } + if (!OldUsersConverter.serverReadyAfterUserconversion(this)) { return false; } else { diff --git a/paper-server/patches/sources/net/minecraft/server/players/GameProfileCache.java.patch b/paper-server/patches/sources/net/minecraft/server/players/GameProfileCache.java.patch index 7f90aa3cd..d7bee7b17 100644 --- a/paper-server/patches/sources/net/minecraft/server/players/GameProfileCache.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/players/GameProfileCache.java.patch @@ -14,11 +14,11 @@ this.safeAdd(usercache_usercacheentry); - this.save(); -+ if( !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly ) this.save(); // Spigot - skip saving if disabled ++ if( !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly ) this.save(true); // Spigot - skip saving if disabled // Paper - Perf: Async GameProfileCache saving } private long getNextOperation() { -@@ -142,14 +142,14 @@ +@@ -142,15 +142,15 @@ usercache_usercacheentry.setLastAccess(this.getNextOperation()); optional = Optional.of(usercache_usercacheentry.getProfile()); } else { @@ -31,10 +31,12 @@ } - if (flag) { +- this.save(); + if (flag && !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) { // Spigot - skip saving if disabled - this.save(); ++ this.save(true); // Paper - Perf: Async GameProfileCache saving } + return optional; @@ -208,7 +208,7 @@ label54: @@ -65,7 +67,12 @@ } catch (JsonParseException | IOException ioexception) { GameProfileCache.LOGGER.warn("Failed to load profile cache {}", this.file, ioexception); } -@@ -261,7 +266,7 @@ +@@ -257,14 +262,15 @@ + return list; + } + +- public void save() { ++ public void save(boolean asyncSave) { // Paper - Perf: Async GameProfileCache saving JsonArray jsonarray = new JsonArray(); DateFormat dateformat = GameProfileCache.createDateFormat(); @@ -74,3 +81,22 @@ jsonarray.add(GameProfileCache.writeGameProfile(usercache_usercacheentry, dateformat)); }); String s = this.gson.toJson(jsonarray); ++ Runnable save = () -> { // Paper - Perf: Async GameProfileCache saving + + try { + BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8); +@@ -289,6 +295,14 @@ + } catch (IOException ioexception) { + ; + } ++ // Paper start - Perf: Async GameProfileCache saving ++ }; ++ if (asyncSave) { ++ io.papermc.paper.util.MCUtil.scheduleAsyncTask(save); ++ } else { ++ save.run(); ++ } ++ // Paper end - Perf: Async GameProfileCache saving + + } +