From b117c35580dd2b4d09fa467b2672f990945767be Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Wed, 26 Aug 2020 20:15:23 +0200 Subject: [PATCH 1/2] improve performance of chunk updates for 1.16.2 --- .../mc1_16_2/BukkitAdapter_1_16_2.java | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java index adac97fe1..5724f95d7 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java @@ -48,6 +48,8 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Function; +import java.util.logging.Level; +import java.util.logging.Logger; public final class BukkitAdapter_1_16_2 extends NMSAdapter { /* @@ -73,7 +75,8 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter { private static final Field fieldLock; - private static final Constructor shortArraySetConstructor; + private static final short[] FULL_CHUNK_SECTION_CHANGE_SET; + private static final Constructor shortArraySetFromShortArrayConstructor; static { try { @@ -115,7 +118,18 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter { throw new Error("data type scale not a power of two"); CHUNKSECTION_SHIFT = 31 - Integer.numberOfLeadingZeros(scale); - shortArraySetConstructor = Class.forName(new String(new char[]{'i','t','.','u','n','i','m','i','.','d','s','i','.','f','a','s','t','u','t','i','l','.','s','h','o','r','t','s','.','S','h','o','r','t','A','r','r','a','y','S','e','t'})).getConstructor(); + Class clsShortArraySet = Class.forName(new String(new char[]{'i','t','.','u','n','i','m','i','.','d','s','i','.','f','a','s','t','u','t','i','l','.','s','h','o','r','t','s','.','S','h','o','r','t','A','r','r','a','y','S','e','t'})); + shortArraySetFromShortArrayConstructor = clsShortArraySet.getConstructor(short[].class); + + FULL_CHUNK_SECTION_CHANGE_SET = new short[16 * 16 * 16]; + for (int x = 0; x < 16; x++) { + for (int y = 0; y < 16; y++) { + for (int z = 0; z < 16; z++) { + short i = (short) ((x << 8) | (z << 4) | y); + FULL_CHUNK_SECTION_CHANGE_SET[i] = i; + } + } + } } catch (RuntimeException e) { throw e; } catch (Throwable rethrow) { @@ -195,11 +209,7 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter { nmsWorld.getChunkProvider().playerChunkMap.a(playerChunk); } for (int i = 0; i < 16; i++) { - if (dirtyblocks[i] == null) dirtyblocks[i] = (Set) shortArraySetConstructor.newInstance(); - for (int x = 0; x < 16; x++) - for (int y = 0; y < 16; y++) - for (int z = 0; z < 16; z++) - dirtyblocks[i].add((short) ((x << 8) | (z << 4) | (y))); + dirtyblocks[i] = getFullChunkSliceChangeSet(); } fieldDirtyBlocks.set(playerChunk, dirtyblocks); @@ -213,13 +223,8 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter { p.playerConnection.sendPacket(packet); }); } - } catch (IllegalAccessException e) { e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } catch (InstantiationException e) { - e.printStackTrace(); } return null; }); @@ -320,4 +325,14 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter { fieldTickingBlockCount.setShort(section, (short) tickingBlockCount); fieldNonEmptyBlockCount.setShort(section, (short) nonEmptyBlockCount); } + + private static Set getFullChunkSliceChangeSet() { + try { + short[] data = new short[16 * 16 * 16]; + System.arraycopy(FULL_CHUNK_SECTION_CHANGE_SET, 0, data, 0, FULL_CHUNK_SECTION_CHANGE_SET.length); + return (Set) shortArraySetFromShortArrayConstructor.newInstance((Object) data); + } catch (Throwable e) { + return null; + } + } } From 9515f3abfc6c46a5925aa7d2661aad619938365c Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Wed, 26 Aug 2020 20:46:48 +0200 Subject: [PATCH 2/2] fix for spigot boooooooooooooooooooooooooooooooooooooooooooo --- .../adapter/mc1_16_2/BukkitAdapter_1_16_2.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java index 5724f95d7..7795ace93 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java @@ -13,8 +13,6 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypesCache; import io.papermc.lib.PaperLib; -import it.unimi.dsi.fastutil.shorts.ShortArraySet; -import it.unimi.dsi.fastutil.shorts.ShortSet; import net.jpountz.util.UnsafeUtils; import net.minecraft.server.v1_16_R2.Block; import net.minecraft.server.v1_16_R2.Chunk; @@ -39,7 +37,6 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; import java.util.HashMap; @@ -48,8 +45,6 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Function; -import java.util.logging.Level; -import java.util.logging.Logger; public final class BukkitAdapter_1_16_2 extends NMSAdapter { /* @@ -118,7 +113,12 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter { throw new Error("data type scale not a power of two"); CHUNKSECTION_SHIFT = 31 - Integer.numberOfLeadingZeros(scale); - Class clsShortArraySet = Class.forName(new String(new char[]{'i','t','.','u','n','i','m','i','.','d','s','i','.','f','a','s','t','u','t','i','l','.','s','h','o','r','t','s','.','S','h','o','r','t','A','r','r','a','y','S','e','t'})); + Class clsShortArraySet; + try { //paper + clsShortArraySet = Class.forName(new String(new char[]{'i', 't', '.', 'u', 'n', 'i', 'm', 'i', '.', 'd', 's', 'i', '.', 'f', 'a', 's', 't', 'u', 't', 'i', 'l', '.', 's', 'h', 'o', 'r', 't', 's', '.', 'S', 'h', 'o', 'r', 't', 'A', 'r', 'r', 'a', 'y', 'S', 'e', 't'})); + } catch (Throwable t) {// still using spigot boooo + clsShortArraySet = Class.forName(new String(new char[]{'o', 'r', 'g', '.', 'b', 'u', 'k', 'k', 'i', 't', '.', 'c', 'r', 'a', 'f', 't', 'b', 'u', 'k', 'k', 'i', 't', '.', 'l', 'i', 'b', 's', '.', 'i', 't', '.', 'u', 'n', 'i', 'm', 'i', '.', 'd', 's', 'i', '.', 'f', 'a', 's', 't', 'u', 't', 'i', 'l', '.', 's', 'h', 'o', 'r', 't', 's', '.', 'S', 'h', 'o', 'r', 't', 'A', 'r', 'r', 'a', 'y', 'S', 'e', 't'})); + } shortArraySetFromShortArrayConstructor = clsShortArraySet.getConstructor(short[].class); FULL_CHUNK_SECTION_CHANGE_SET = new short[16 * 16 * 16];