From b415ceb6175407f601a0dd95621fdc047ecafda8 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Thu, 16 Apr 2020 20:47:15 -0700 Subject: [PATCH] Optimize ChunkProviderServer's chunk level checking helper methods These can be hot functions (i.e entity ticking and block ticking), so inline where possible, and avoid the abstraction of the Either class. --- ...oviderServer-s-chunk-level-checking-.patch | 63 +++++++++++++++++++ .../Reduce-Either-Optional-allocation.patch | 22 +++---- 2 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 Spigot-Server-Patches/Optimize-ChunkProviderServer-s-chunk-level-checking-.patch diff --git a/Spigot-Server-Patches/Optimize-ChunkProviderServer-s-chunk-level-checking-.patch b/Spigot-Server-Patches/Optimize-ChunkProviderServer-s-chunk-level-checking-.patch new file mode 100644 index 000000000..f522a774a --- /dev/null +++ b/Spigot-Server-Patches/Optimize-ChunkProviderServer-s-chunk-level-checking-.patch @@ -0,0 +1,63 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Spottedleaf +Date: Thu, 16 Apr 2020 16:13:59 -0700 +Subject: [PATCH] Optimize ChunkProviderServer's chunk level checking helper + methods + +These can be hot functions (i.e entity ticking and block ticking), +so inline where possible, and avoid the abstraction of the +Either class. + +diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java +index f741a034e..664a244dd 100644 +--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java ++++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java +@@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider { + + public final boolean isInEntityTickingChunk(Entity entity) { return this.a(entity); } // Paper - OBFHELPER + @Override public boolean a(Entity entity) { +- long i = ChunkCoordIntPair.pair(MathHelper.floor(entity.locX()) >> 4, MathHelper.floor(entity.locZ()) >> 4); +- +- return this.a(i, PlayerChunk::b); ++ // Paper start - optimize is ticking ready type functions ++ // entity ticking ++ PlayerChunk playerChunk = this.getChunk(MCUtil.getCoordinateKey(entity)); ++ return playerChunk != null && playerChunk.isEntityTickingReady(); ++ // Paper end - optimize is ticking ready type functions + } + + public final boolean isEntityTickingChunk(ChunkCoordIntPair chunkcoordintpair) { return this.a(chunkcoordintpair); } // Paper - OBFHELPER + @Override public boolean a(ChunkCoordIntPair chunkcoordintpair) { +- return this.a(chunkcoordintpair.pair(), PlayerChunk::b); ++ // Paper start - optimize is ticking ready type functions ++ // is entity ticking ready ++ PlayerChunk playerChunk = this.getChunk(MCUtil.getCoordinateKey(chunkcoordintpair)); ++ return playerChunk != null && playerChunk.isEntityTickingReady(); ++ // Paper end - optimize is ticking ready type functions + } + + @Override + public boolean a(BlockPosition blockposition) { +- long i = ChunkCoordIntPair.pair(blockposition.getX() >> 4, blockposition.getZ() >> 4); +- +- return this.a(i, PlayerChunk::a); ++ // Paper start - optimize is ticking ready type functions ++ // is ticking ready ++ PlayerChunk playerChunk = this.getChunk(MCUtil.getCoordinateKey(blockposition)); ++ return playerChunk != null && playerChunk.isTickingReady(); ++ // Paper end - optimize is ticking ready type functions + } + + public boolean b(Entity entity) { +- long i = ChunkCoordIntPair.pair(MathHelper.floor(entity.locX()) >> 4, MathHelper.floor(entity.locZ()) >> 4); +- +- return this.a(i, PlayerChunk::c); ++ // Paper start - optimize is ticking ready type functions ++ // is full chunk ready ++ PlayerChunk playerChunk = this.getChunk(MCUtil.getCoordinateKey(entity)); ++ return playerChunk != null && playerChunk.isFullChunkReady(); ++ // Paper end - optimize is ticking ready type functions + } + + private boolean a(long i, Function>> function) { +-- \ No newline at end of file diff --git a/Spigot-Server-Patches/Reduce-Either-Optional-allocation.patch b/Spigot-Server-Patches/Reduce-Either-Optional-allocation.patch index 9d666e112..c75753652 100644 --- a/Spigot-Server-Patches/Reduce-Either-Optional-allocation.patch +++ b/Spigot-Server-Patches/Reduce-Either-Optional-allocation.patch @@ -7,7 +7,7 @@ In order to get chunk values, we shouldn't need to create an optional each time. diff --git a/src/main/java/com/mojang/datafixers/util/Either.java b/src/main/java/com/mojang/datafixers/util/Either.java -index a90adac7b..4bb621d57 100644 +index a90adac7b..3f65fe710 100644 --- a/src/main/java/com/mojang/datafixers/util/Either.java +++ b/src/main/java/com/mojang/datafixers/util/Either.java @@ -0,0 +0,0 @@ public abstract class Either implements App, L> { @@ -15,20 +15,16 @@ index a90adac7b..4bb621d57 100644 private static final class Left extends Either { - private final L value; -+ private final L value; private final Optional valueOptional; // Paper - reduce the optional allocation... ++ private final L value; private Optional valueOptional; // Paper - reduce the optional allocation... public Left(final L value) { -- this.value = value; -+ this.value = value; this.valueOptional = value != null ? Optional.of(value) : Optional.empty(); // Paper - reduce the optional allocation... - } - - @Override + this.value = value; @@ -0,0 +0,0 @@ public abstract class Either implements App, L> { @Override public Optional left() { - return Optional.of(value); -+ return this.valueOptional; // Paper - reduce the optional allocation... ++ return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - reduce the optional allocation... } @Override @@ -37,20 +33,16 @@ index a90adac7b..4bb621d57 100644 private static final class Right extends Either { - private final R value; -+ private final R value; private final Optional valueOptional; // Paper - reduce the optional allocation... ++ private final R value; private Optional valueOptional; // Paper - reduce the optional allocation... public Right(final R value) { -- this.value = value; -+ this.value = value; this.valueOptional = value != null ? Optional.of(value) : Optional.empty(); // Paper - reduce the optional allocation... - } - - @Override + this.value = value; @@ -0,0 +0,0 @@ public abstract class Either implements App, L> { @Override public Optional right() { - return Optional.of(value); -+ return this.valueOptional; // Paper - reduce the optional allocation... ++ return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - reduce the optional allocation... } @Override