From 1f2c93586be61b0c3cd70b69dab414159a31692b Mon Sep 17 00:00:00 2001 From: Marco Date: Sun, 3 May 2026 13:50:59 +0200 Subject: [PATCH 1/3] Optimize waypoint distance check --- .../0001-Moonrise-optimisation-patches.patch | 6 +++--- .../world/waypoints/WaypointTransmitter.java.patch | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch b/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch index 2f5fc143544b..748fd086714a 100644 --- a/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch +++ b/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch @@ -28453,7 +28453,7 @@ index c974b6cafb1f6aa2a57cfdc8a39c887f02f42b1d..ec40f02032f965f548b0c0a29aa9d9bb // Paper start - PlayerChunkLoadEvent if (io.papermc.paper.event.packet.PlayerChunkLoadEvent.getHandlerList().getRegisteredListeners().length > 0) { diff --git a/net/minecraft/server/network/config/PrepareSpawnTask.java b/net/minecraft/server/network/config/PrepareSpawnTask.java -index 83af9ee3ba150da85b9b694cd76a5fabb5b2d8ef..1fb40837bd02672850ec9adc2797190df22b33fc 100644 +index b5d993095aa77bb132c513f73dbf6d2afb2e3943..8b318dd8aa918284c5fa89e990b13bec425102cb 100644 --- a/net/minecraft/server/network/config/PrepareSpawnTask.java +++ b/net/minecraft/server/network/config/PrepareSpawnTask.java @@ -171,7 +171,7 @@ public class PrepareSpawnTask implements ConfigurationTask { @@ -36949,10 +36949,10 @@ index 082258e7d8270d4026a70a5c0a9e1228d70a2e8d..c3825e91504f5df6bfd8e41de1f5dc4a for (SavedTick pendingTick : this.pendingTicks) { diff --git a/net/minecraft/world/waypoints/WaypointTransmitter.java b/net/minecraft/world/waypoints/WaypointTransmitter.java -index d785e9a69a109d1d7ce7a7e182c215f3d6a35b64..d6f842cbd2060eb56a1e4384b3ea97feea3e73ba 100644 +index ce9e6cc47fc26acf7253d27ac9a587bfad8ce8ff..f8230867b75a25e385475a43b4604e379c0661ea 100644 --- a/net/minecraft/world/waypoints/WaypointTransmitter.java +++ b/net/minecraft/world/waypoints/WaypointTransmitter.java -@@ -34,7 +34,10 @@ public interface WaypointTransmitter extends Waypoint { +@@ -38,7 +38,10 @@ public interface WaypointTransmitter extends Waypoint { } static boolean isChunkVisible(final ChunkPos chunkPos, final ServerPlayer receiver) { diff --git a/paper-server/patches/sources/net/minecraft/world/waypoints/WaypointTransmitter.java.patch b/paper-server/patches/sources/net/minecraft/world/waypoints/WaypointTransmitter.java.patch index a8da863bf0c6..b85f9aa5d29a 100644 --- a/paper-server/patches/sources/net/minecraft/world/waypoints/WaypointTransmitter.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/waypoints/WaypointTransmitter.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/waypoints/WaypointTransmitter.java +++ b/net/minecraft/world/waypoints/WaypointTransmitter.java -@@ -20,6 +_,7 @@ +@@ -20,13 +_,18 @@ Waypoint.Icon waypointIcon(); static boolean doesSourceIgnoreReceiver(final LivingEntity source, final ServerPlayer receiver) { @@ -8,3 +8,15 @@ if (receiver.isSpectator()) { return false; } else if (!source.isSpectator() && !source.hasIndirectPassenger(receiver)) { + double broadcastRange = Math.min( + source.getAttributeValue(Attributes.WAYPOINT_TRANSMIT_RANGE), receiver.getAttributeValue(Attributes.WAYPOINT_RECEIVE_RANGE) + ); +- return source.distanceTo(receiver) >= broadcastRange; ++ // Paper start - optimize waypoint distance check by using squared distance ++ if (broadcastRange <= 0) ++ return true; ++ return source.distanceToSqr(receiver) >= broadcastRange*broadcastRange; ++ // Paper end - optimize waypoint distance check by using squared distance + } else { + return true; + } From 54c2e085db26b9466c861b73c0ffa22d8e82f6dc Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Wed, 13 May 2026 19:15:57 +0200 Subject: [PATCH 2/3] [ci skip] format --- .../features/0001-Moonrise-optimisation-patches.patch | 4 ++-- .../world/waypoints/WaypointTransmitter.java.patch | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch b/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch index 748fd086714a..6f0240cca01f 100644 --- a/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch +++ b/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch @@ -36949,10 +36949,10 @@ index 082258e7d8270d4026a70a5c0a9e1228d70a2e8d..c3825e91504f5df6bfd8e41de1f5dc4a for (SavedTick pendingTick : this.pendingTicks) { diff --git a/net/minecraft/world/waypoints/WaypointTransmitter.java b/net/minecraft/world/waypoints/WaypointTransmitter.java -index ce9e6cc47fc26acf7253d27ac9a587bfad8ce8ff..f8230867b75a25e385475a43b4604e379c0661ea 100644 +index ce1f4c4c2c6a28b100da367f26f7be5f77f99d60..aed31c00289eee5ed3c858d0cac3796503016d38 100644 --- a/net/minecraft/world/waypoints/WaypointTransmitter.java +++ b/net/minecraft/world/waypoints/WaypointTransmitter.java -@@ -38,7 +38,10 @@ public interface WaypointTransmitter extends Waypoint { +@@ -37,7 +37,10 @@ public interface WaypointTransmitter extends Waypoint { } static boolean isChunkVisible(final ChunkPos chunkPos, final ServerPlayer receiver) { diff --git a/paper-server/patches/sources/net/minecraft/world/waypoints/WaypointTransmitter.java.patch b/paper-server/patches/sources/net/minecraft/world/waypoints/WaypointTransmitter.java.patch index b85f9aa5d29a..cb56a906c807 100644 --- a/paper-server/patches/sources/net/minecraft/world/waypoints/WaypointTransmitter.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/waypoints/WaypointTransmitter.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/waypoints/WaypointTransmitter.java +++ b/net/minecraft/world/waypoints/WaypointTransmitter.java -@@ -20,13 +_,18 @@ +@@ -20,13 +_,17 @@ Waypoint.Icon waypointIcon(); static boolean doesSourceIgnoreReceiver(final LivingEntity source, final ServerPlayer receiver) { @@ -13,9 +13,8 @@ ); - return source.distanceTo(receiver) >= broadcastRange; + // Paper start - optimize waypoint distance check by using squared distance -+ if (broadcastRange <= 0) -+ return true; -+ return source.distanceToSqr(receiver) >= broadcastRange*broadcastRange; ++ if (broadcastRange <= 0) return true; ++ return source.distanceToSqr(receiver) >= Mth.square(broadcastRange); + // Paper end - optimize waypoint distance check by using squared distance } else { return true; From d0b864da3725e092f4b4bdebde58872daa0d1691 Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Sat, 25 Jul 2026 14:51:11 +0100 Subject: [PATCH 3/3] Drop non hot path early returns --- .../features/0001-Moonrise-optimisation-patches.patch | 4 ++-- .../world/waypoints/WaypointTransmitter.java.patch | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch b/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch index b760c6cc969f..327731cf212a 100644 --- a/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch +++ b/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch @@ -36909,10 +36909,10 @@ index cec7442a5401b2886f5ce7c473386c15f64fe0a3..88eb48034d8022600dc08b4dcf6162bb for (SavedTick pendingTick : this.pendingTicks) { diff --git a/net/minecraft/world/waypoints/WaypointTransmitter.java b/net/minecraft/world/waypoints/WaypointTransmitter.java -index e822b8429e8ea2b113ef83310223bc7edb12aad9..2866b750a28cc32c2913d3c1afee95f05956982c 100644 +index 01fd20a4a452de5201f4e6141d6fb7563e2597b4..07af92310ee5c8bba04e6175b6faac629632e4de 100644 --- a/net/minecraft/world/waypoints/WaypointTransmitter.java +++ b/net/minecraft/world/waypoints/WaypointTransmitter.java -@@ -37,7 +37,10 @@ public interface WaypointTransmitter extends Waypoint { +@@ -34,7 +34,10 @@ public interface WaypointTransmitter extends Waypoint { } static boolean isChunkVisible(final ChunkPos chunkPos, final ServerPlayer receiver) { diff --git a/paper-server/patches/sources/net/minecraft/world/waypoints/WaypointTransmitter.java.patch b/paper-server/patches/sources/net/minecraft/world/waypoints/WaypointTransmitter.java.patch index cb56a906c807..de07b227b4f7 100644 --- a/paper-server/patches/sources/net/minecraft/world/waypoints/WaypointTransmitter.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/waypoints/WaypointTransmitter.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/waypoints/WaypointTransmitter.java +++ b/net/minecraft/world/waypoints/WaypointTransmitter.java -@@ -20,13 +_,17 @@ +@@ -20,13 +_,14 @@ Waypoint.Icon waypointIcon(); static boolean doesSourceIgnoreReceiver(final LivingEntity source, final ServerPlayer receiver) { @@ -12,10 +12,7 @@ source.getAttributeValue(Attributes.WAYPOINT_TRANSMIT_RANGE), receiver.getAttributeValue(Attributes.WAYPOINT_RECEIVE_RANGE) ); - return source.distanceTo(receiver) >= broadcastRange; -+ // Paper start - optimize waypoint distance check by using squared distance -+ if (broadcastRange <= 0) return true; -+ return source.distanceToSqr(receiver) >= Mth.square(broadcastRange); -+ // Paper end - optimize waypoint distance check by using squared distance ++ return source.distanceToSqr(receiver) >= Mth.square(broadcastRange); // Paper - optimize waypoint distance check by using squared distance } else { return true; }