diff --git a/patches/server/0015-Tuinity-Use-ArrayDeque-for-pendingChunkUpdates-in-Ch.patch b/patches/server/0015-Tuinity-Use-ArrayDeque-for-pendingChunkUpdates-in-Ch.patch new file mode 100644 index 000000000..16c0515fc --- /dev/null +++ b/patches/server/0015-Tuinity-Use-ArrayDeque-for-pendingChunkUpdates-in-Ch.patch @@ -0,0 +1,23 @@ +From 2dfe97b203e00b20d2ce623d7937192f4bb8a3e0 Mon Sep 17 00:00:00 2001 +From: Sotr +Date: Wed, 15 Apr 2020 02:39:12 +0700 +Subject: [PATCH] Tuinity Use ArrayDeque for pendingChunkUpdates in + ChunkMapDistance + + +diff --git a/src/main/java/net/minecraft/server/ChunkMapDistance.java b/src/main/java/net/minecraft/server/ChunkMapDistance.java +index 0244768f7..13d113aee 100644 +--- a/src/main/java/net/minecraft/server/ChunkMapDistance.java ++++ b/src/main/java/net/minecraft/server/ChunkMapDistance.java +@@ -33,7 +33,7 @@ public abstract class ChunkMapDistance { + private final ChunkMapDistance.a e = new ChunkMapDistance.a(); + private final ChunkMapDistance.b f = new ChunkMapDistance.b(8); + private final ChunkMapDistance.c g = new ChunkMapDistance.c(33); +- private final java.util.Queue pendingChunkUpdates = new java.util.LinkedList<>(); // PAIL pendingChunkUpdates // Paper - use a queue ++ private final java.util.Queue pendingChunkUpdates = new java.util.ArrayDeque<>(); // PAIL pendingChunkUpdates // Paper - use a queue // Akarin - backport Tuinity - use a better queue + private final ChunkTaskQueueSorter i; + private final Mailbox> j; + private final Mailbox k; +-- +2.25.1.windows.1 + diff --git a/patches/server/0016-Tuinity-Optimise-ArraySetSorted-removeIf.patch b/patches/server/0016-Tuinity-Optimise-ArraySetSorted-removeIf.patch new file mode 100644 index 000000000..ab486e5de --- /dev/null +++ b/patches/server/0016-Tuinity-Optimise-ArraySetSorted-removeIf.patch @@ -0,0 +1,67 @@ +From 96cfd7cd2b51c4ca8e39031fd654ec70dae16e53 Mon Sep 17 00:00:00 2001 +From: Sotr +Date: Wed, 15 Apr 2020 02:44:07 +0700 +Subject: [PATCH] Tuinity Optimise ArraySetSorted#removeIf + +Remove iterator allocation and ensure the call is always O(n) + +diff --git a/src/main/java/net/minecraft/server/ArraySetSorted.java b/src/main/java/net/minecraft/server/ArraySetSorted.java +index 85f799a71..f23ddb9e0 100644 +--- a/src/main/java/net/minecraft/server/ArraySetSorted.java ++++ b/src/main/java/net/minecraft/server/ArraySetSorted.java +@@ -11,7 +11,9 @@ public class ArraySetSorted extends AbstractSet { + + private final Comparator a; + private T[] b; ++ private final T[] getBackingArray() { return this.b; } // Akarin - OBFHELPER + private int c; ++ private final int getSize() { return this.c; } private final void setSize(int value) { this.c = value; } // Akarin - OBFHELPER + + private ArraySetSorted(int i, Comparator comparator) { + this.a = comparator; +@@ -22,6 +24,42 @@ public class ArraySetSorted extends AbstractSet { + } + } + ++ // Akarin start - backport Tuinity - optimise removeIf ++ @Override ++ public boolean removeIf(java.util.function.Predicate filter) { ++ // prev. impl used an iterator, which could be n^2 ++ int i = 0, len = this.getSize(); ++ T[] backingArray = this.getBackingArray(); ++ ++ for (;;) { ++ if (i >= len) { ++ return false; ++ } ++ if (!filter.test(backingArray[i])) { ++ ++i; ++ continue; ++ } ++ break; ++ } ++ ++ // we only want to write back to backingArray if we really need to ++ ++ int lastIndex = i; // this is where new elements are shifted to ++ ++ for (; i < len; ++i) { ++ T curr = backingArray[i]; ++ if (!filter.test(curr)) { // if test throws we're screwed ++ backingArray[lastIndex++] = curr; ++ } ++ } ++ ++ // cleanup end ++ Arrays.fill(backingArray, lastIndex, len, null); ++ this.setSize(lastIndex); ++ return true; ++ } ++ // Akarin end - backport Tuinity - optimise removeIf ++ + public static > ArraySetSorted a(int i) { + return new ArraySetSorted<>(i, (Comparator)Comparator.naturalOrder()); // Paper - decompile fix + } +-- +2.25.1.windows.1 + diff --git a/patches/server/0017-Don-t-run-entity-collision-code-if-not-needed.patch b/patches/server/0017-Don-t-run-entity-collision-code-if-not-needed.patch new file mode 100644 index 000000000..8520b7490 --- /dev/null +++ b/patches/server/0017-Don-t-run-entity-collision-code-if-not-needed.patch @@ -0,0 +1,35 @@ +From d3184b59d0a3febbe940915a77d28b1cfcb6fd13 Mon Sep 17 00:00:00 2001 +From: Sotr +Date: Wed, 15 Apr 2020 02:49:56 +0700 +Subject: [PATCH] Don't run entity collision code if not needed + +Will not run if max entity craming is disabled and +the max collisions per entity is less than or equal to 0 + +This commit was basically referenced on Tunity#7131da4. + +diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java +index e93b7b280..3beeb05b1 100644 +--- a/src/main/java/net/minecraft/server/EntityLiving.java ++++ b/src/main/java/net/minecraft/server/EntityLiving.java +@@ -2663,10 +2663,16 @@ public abstract class EntityLiving extends Entity { + protected void doTick() {} + + protected void collideNearby() { ++ // Akarin start - don't run getEntities if we're not going to use its result ++ if (world.paperConfig.maxCollisionsPerEntity <= 0) return; ++ ++ int i = this.world.getGameRules().getInt(GameRules.MAX_ENTITY_CRAMMING); ++ if (i <= 0) return; ++ // Akarin end + List list = this.world.getEntities(this, this.getBoundingBox(), IEntitySelector.a(this)); + + if (!list.isEmpty()) { +- int i = this.world.getGameRules().getInt(GameRules.MAX_ENTITY_CRAMMING); ++ // int i = this.world.getGameRules().getInt(GameRules.MAX_ENTITY_CRAMMING); // Akarin - moved up + int j; + + if (i > 0 && list.size() > i - 1 && this.random.nextInt(4) == 0) { +-- +2.25.1.windows.1 +