Multiple patches backported from Tuinity

This commit is contained in:
Sotr
2020-04-15 02:52:10 +07:00
parent e4cdd73478
commit 177baf669a
3 changed files with 125 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
From 2dfe97b203e00b20d2ce623d7937192f4bb8a3e0 Mon Sep 17 00:00:00 2001
From: Sotr <i@omc.hk>
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<PlayerChunk> pendingChunkUpdates = new java.util.LinkedList<>(); // PAIL pendingChunkUpdates // Paper - use a queue
+ private final java.util.Queue<PlayerChunk> 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<ChunkTaskQueueSorter.a<Runnable>> j;
private final Mailbox<ChunkTaskQueueSorter.b> k;
--
2.25.1.windows.1

View File

@@ -0,0 +1,67 @@
From 96cfd7cd2b51c4ca8e39031fd654ec70dae16e53 Mon Sep 17 00:00:00 2001
From: Sotr <i@omc.hk>
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<T> extends AbstractSet<T> {
private final Comparator<T> 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<T> comparator) {
this.a = comparator;
@@ -22,6 +24,42 @@ public class ArraySetSorted<T> extends AbstractSet<T> {
}
}
+ // Akarin start - backport Tuinity - optimise removeIf
+ @Override
+ public boolean removeIf(java.util.function.Predicate<? super T> 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 <T extends Comparable<T>> ArraySetSorted<T> a(int i) {
return new ArraySetSorted<>(i, (Comparator)Comparator.naturalOrder()); // Paper - decompile fix
}
--
2.25.1.windows.1

View File

@@ -0,0 +1,35 @@
From d3184b59d0a3febbe940915a77d28b1cfcb6fd13 Mon Sep 17 00:00:00 2001
From: Sotr <i@omc.hk>
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<Entity> 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