9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-31 04:46:38 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0105-Akarin-Save-Json-list-asynchronously.patch
Dreeam 9a4efaa230 Drop patch that causes performance regression
Originally vanilla logic is to use stream, and Mojang switched it to Guava's Collections2
since 1.21.4. It is much faster than using stream or manually adding to a new ArrayList.
Manually adding to a new ArrayList requires allocating a new object array. However, the Collections2
lazy handles filter condition on iteration, so much better.
2025-08-04 19:25:56 +08:00

38 lines
1.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E3=84=97=E3=84=A0=CB=8B=20=E3=84=91=E3=84=A7=CB=8A?=
<tsao-chi@the-lingo.org>
Date: Thu, 5 Jan 2023 09:08:17 +0800
Subject: [PATCH] Akarin: Save Json list asynchronously
Original license: GPL v3
Original project: https://github.com/Akarin-project/Akarin
diff --git a/net/minecraft/server/players/StoredUserList.java b/net/minecraft/server/players/StoredUserList.java
index 39483f7b453d6faedeccc1ab1eda76669395ea5a..1fe9be5381b43d240593c8394977d7ffccd1132b 100644
--- a/net/minecraft/server/players/StoredUserList.java
+++ b/net/minecraft/server/players/StoredUserList.java
@@ -97,13 +97,23 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
}
public void save() throws IOException {
+ Runnable saveTask = () -> {// Leaf - Akarin - Save Json list asynchronously
this.removeExpired(); // Paper - remove expired values before saving
JsonArray jsonArray = new JsonArray();
this.map.values().stream().map(storedEntry -> Util.make(new JsonObject(), storedEntry::serialize)).forEach(jsonArray::add);
+ try { // Leaf - Akarin - Save Json list asynchronously
try (BufferedWriter writer = Files.newWriter(this.file, StandardCharsets.UTF_8)) {
GSON.toJson(jsonArray, GSON.newJsonWriter(writer));
}
+
+ // Leaf start - Akarin - Save Json list asynchronously
+ } catch (Exception e) {
+ StoredUserList.LOGGER.warn("Failed to save {} asynchronously", this.file, e);
+ }
+ };
+ io.papermc.paper.util.MCUtil.scheduleAsyncTask(saveTask);
+ // Leaf end - Akarin - Save Json list asynchronously
}
public void load() throws IOException {