From e4331844ace9e7b9ed8281239e1c9e97a203fa81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= <43724816+Aurelien30000@users.noreply.github.com> Date: Tue, 13 Apr 2021 16:55:12 +0200 Subject: [PATCH 1/2] Fix performance issues getting next file ids (#1027) * Greetly optimize disk history * Greetly optimize disk cfi changeset * Remove wildcard import. * Improve performance fix * Improved performance fix --- .../boydti/fawe/object/changeset/CFIChangeSet.java | 13 +++++++++++-- .../fawe/object/changeset/DiskStorageHistory.java | 11 +++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/CFIChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/CFIChangeSet.java index 83bcee1ce..7fe5c9f3a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/CFIChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/CFIChangeSet.java @@ -12,17 +12,26 @@ import com.sk89q.worldedit.world.biome.BiomeType; import java.io.File; import java.io.IOException; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; public class CFIChangeSet extends AbstractChangeSet { + private static final Map> NEXT_INDEX = new ConcurrentHashMap<>(); + private final File file; public CFIChangeSet(HeightMapMCAGenerator hmmg, UUID uuid) throws IOException { super(hmmg); - File folder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HISTORY + File.separator + uuid + File.separator + "CFI" + File.separator + hmmg.getId()); - int max = MainUtil.getMaxFileId(folder); + final String hmmgId = hmmg.getId(); + final File folder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HISTORY + File.separator + uuid + File.separator + "CFI" + File.separator + hmmgId); + + final int max = NEXT_INDEX.computeIfAbsent(uuid, _uuid -> new HashMap<>()) + .compute(hmmgId, (_hmmgId, id) -> (id == null ? MainUtil.getMaxFileId(folder) : id) + 1) - 1; + this.file = new File(folder, max + ".cfi"); File parent = this.file.getParentFile(); if (!parent.exists()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index 296887527..7e4b9078e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -19,7 +19,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; /** * Store the change on disk @@ -30,6 +32,8 @@ import java.util.UUID; */ public class DiskStorageHistory extends FaweStreamChangeSet { + private static final Map> NEXT_INDEX = new ConcurrentHashMap<>(); + private UUID uuid; private File bdFile; private File bioFile; @@ -67,8 +71,11 @@ public class DiskStorageHistory extends FaweStreamChangeSet { } private void init(UUID uuid, String worldName) { - File folder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HISTORY + File.separator + worldName + File.separator + uuid); - int max = MainUtil.getMaxFileId(folder); + final File folder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HISTORY + File.separator + worldName + File.separator + uuid); + + final int max = NEXT_INDEX.computeIfAbsent(worldName, _worldName -> new ConcurrentHashMap<>()) + .compute(uuid, (_uuid, id) -> (id == null ? MainUtil.getMaxFileId(folder) : id) + 1) - 1; + init(uuid, max); } From 8b69d8a8e2eee74df81beb21cc0d8b250582d0c7 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Wed, 14 Apr 2021 10:05:16 +0200 Subject: [PATCH 2/2] Improve outdated note even more --- .../com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java index 0398801b6..7be04b391 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java @@ -50,7 +50,7 @@ public class BukkitImplLoader { "\n**********************************************\n" + "** This FastAsyncWorldEdit version does not fully support your version of Bukkit.\n" + "** You can fix this by:\n" - + "** - Updating your server version\n** - Updating FAWE\n" + + "** - Updating your server version (Check /version to see how many versions you are behind)\n** - Updating FAWE\n" + "**\n" + "** When working with blocks or undoing, chests will be empty, signs\n" + "** will be blank, and so on. There will be no support for entity\n" + "** and block property-related functions.\n"