aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0992-Optimize-isInWorldBounds-and-getBlockState-for-inlin.patch
diff options
context:
space:
mode:
authorNassim Jahnke <[email protected]>2024-06-15 19:24:11 +0200
committerNassim Jahnke <[email protected]>2024-06-15 19:24:11 +0200
commit0008fa17e967aa435e70fb881edf91b47c8aec7c (patch)
treea7c4761daacba843291d0e98dd133ca49ef11d80 /patches/server/0992-Optimize-isInWorldBounds-and-getBlockState-for-inlin.patch
parent04dad71064013b47a0c47e269ae41b4fea4f8336 (diff)
downloadPaper-0008fa17e967aa435e70fb881edf91b47c8aec7c.tar.gz
Paper-0008fa17e967aa435e70fb881edf91b47c8aec7c.zip
Add back more optimization patches
Diffstat (limited to 'patches/server/0992-Optimize-isInWorldBounds-and-getBlockState-for-inlin.patch')
-rw-r--r--patches/server/0992-Optimize-isInWorldBounds-and-getBlockState-for-inlin.patch99
1 files changed, 99 insertions, 0 deletions
diff --git a/patches/server/0992-Optimize-isInWorldBounds-and-getBlockState-for-inlin.patch b/patches/server/0992-Optimize-isInWorldBounds-and-getBlockState-for-inlin.patch
new file mode 100644
index 0000000000..2cdcbebb6f
--- /dev/null
+++ b/patches/server/0992-Optimize-isInWorldBounds-and-getBlockState-for-inlin.patch
@@ -0,0 +1,99 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Aikar <[email protected]>
+Date: Thu, 3 Mar 2016 02:07:55 -0600
+Subject: [PATCH] Optimize isInWorldBounds and getBlockState for inlining
+
+Hot methods, so reduce # of instructions for the method.
+
+Move is valid location test to the BlockPosition class so that it can access local variables.
+
+Replace all calls to the new place to the unnecessary forward.
+
+Optimize getType and getBlockData to manually inline and optimize the calls
+
+diff --git a/src/main/java/net/minecraft/core/Vec3i.java b/src/main/java/net/minecraft/core/Vec3i.java
+index 02367ef1371dde94ff6c4cd40bd32e800d6ccaaf..7b0fc7135bc107103dcaed6dc0707b1829928fae 100644
+--- a/src/main/java/net/minecraft/core/Vec3i.java
++++ b/src/main/java/net/minecraft/core/Vec3i.java
+@@ -28,6 +28,12 @@ public class Vec3i implements Comparable<Vec3i> {
+ );
+ }
+
++ // Paper start
++ public final boolean isInsideBuildHeightAndWorldBoundsHorizontal(net.minecraft.world.level.LevelHeightAccessor levelHeightAccessor) {
++ return getX() >= -30000000 && getZ() >= -30000000 && getX() < 30000000 && getZ() < 30000000 && !levelHeightAccessor.isOutsideBuildHeight(getY());
++ }
++ // Paper end
++
+ public Vec3i(int x, int y, int z) {
+ this.x = x;
+ this.y = y;
+diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
+index 77c6613c39e3b266944e28cf2627483d9f32c511..b3a433786fabf6f2cfba2cdc8d21f6447191a310 100644
+--- a/src/main/java/net/minecraft/world/level/Level.java
++++ b/src/main/java/net/minecraft/world/level/Level.java
+@@ -394,7 +394,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
+ // Paper end
+
+ public boolean isInWorldBounds(BlockPos pos) {
+- return !this.isOutsideBuildHeight(pos) && Level.isInWorldBoundsHorizontal(pos);
++ return pos.isInsideBuildHeightAndWorldBoundsHorizontal(this); // Paper - use better/optimized check
+ }
+
+ public static boolean isInSpawnableBounds(BlockPos pos) {
+diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java b/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
+index fb7bdf43fdc4d816b1c1f1f063bc170561c9544f..2822a9b010e6d45f9562950a94f1942784db9784 100644
+--- a/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
++++ b/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
+@@ -181,6 +181,7 @@ public abstract class ChunkAccess implements BlockGetter, BiomeManager.NoiseBiom
+ return GameEventListenerRegistry.NOOP;
+ }
+
++ public abstract BlockState getBlockState(final int x, final int y, final int z); // Paper
+ @Nullable
+ public abstract BlockState setBlockState(BlockPos pos, BlockState state, boolean moved);
+
+diff --git a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
+index 4af698930712389881601069a921f054c07935f2..d7d332d8ba3442887e80d2c3d7bddb9de2674c2d 100644
+--- a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
++++ b/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
+@@ -99,6 +99,12 @@ public class ImposterProtoChunk extends ProtoChunk implements ca.spottedleaf.moo
+ public BlockState getBlockState(BlockPos pos) {
+ return this.wrapped.getBlockState(pos);
+ }
++ // Paper start
++ @Override
++ public final BlockState getBlockState(final int x, final int y, final int z) {
++ return this.wrapped.getBlockStateFinal(x, y, z);
++ }
++ // Paper end
+
+ @Override
+ public FluidState getFluidState(BlockPos pos) {
+diff --git a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
+index 207dc31afcf5ca5a59ab27ee263aa10f94a79559..082eae7032d5a8055a0f67b8a5583bbbf6fa9916 100644
+--- a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
++++ b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
+@@ -97,14 +97,18 @@ public class ProtoChunk extends ChunkAccess {
+
+ @Override
+ public BlockState getBlockState(BlockPos pos) {
+- int i = pos.getY();
+- if (this.isOutsideBuildHeight(i)) {
++ // Paper start
++ return getBlockState(pos.getX(), pos.getY(), pos.getZ());
++ }
++ public BlockState getBlockState(final int x, final int y, final int z) {
++ if (this.isOutsideBuildHeight(y)) {
+ return Blocks.VOID_AIR.defaultBlockState();
+ } else {
+- LevelChunkSection levelChunkSection = this.getSection(this.getSectionIndex(i));
+- return levelChunkSection.hasOnlyAir() ? Blocks.AIR.defaultBlockState() : levelChunkSection.getBlockState(pos.getX() & 15, i & 15, pos.getZ() & 15);
++ LevelChunkSection levelChunkSection = this.getSections()[this.getSectionIndex(y)];
++ return levelChunkSection.hasOnlyAir() ? Blocks.AIR.defaultBlockState() : levelChunkSection.getBlockState(x & 15, y & 15, z & 15);
+ }
+ }
++ // Paper end
+
+ @Override
+ public FluidState getFluidState(BlockPos pos) {