aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/1005-Optimize-Pathfinder-Remove-Streams-Optimized-collect.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/server/1005-Optimize-Pathfinder-Remove-Streams-Optimized-collect.patch')
-rw-r--r--patches/server/1005-Optimize-Pathfinder-Remove-Streams-Optimized-collect.patch9
1 files changed, 5 insertions, 4 deletions
diff --git a/patches/server/1005-Optimize-Pathfinder-Remove-Streams-Optimized-collect.patch b/patches/server/1005-Optimize-Pathfinder-Remove-Streams-Optimized-collect.patch
index 8ed7b79355..c0caf10bb5 100644
--- a/patches/server/1005-Optimize-Pathfinder-Remove-Streams-Optimized-collect.patch
+++ b/patches/server/1005-Optimize-Pathfinder-Remove-Streams-Optimized-collect.patch
@@ -16,7 +16,7 @@ This lets us get faster foreach iteration, as well as avoids map lookups on
the values when needed.
diff --git a/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java b/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
-index 3e27c9a74c38f11a436df8cd413f9f5f16fd8c3e..c4d6b145d54aaf415dd4b08811c024255092e1b8 100644
+index a2e7040df11a0138c706a10b190111b6c3bd99a9..ab6e1221a637511553ddd1af6ff3f0d9d9a6de76 100644
--- a/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
+++ b/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
@@ -38,8 +38,12 @@ public class PathFinder {
@@ -24,7 +24,7 @@ index 3e27c9a74c38f11a436df8cd413f9f5f16fd8c3e..c4d6b145d54aaf415dd4b08811c02425
return null;
} else {
- Map<Target, BlockPos> map = positions.stream()
-- .collect(Collectors.toMap(pos -> this.nodeEvaluator.getGoal(pos.getX(), pos.getY(), pos.getZ()), Function.identity()));
+- .collect(Collectors.toMap(pos -> this.nodeEvaluator.getGoal((double)pos.getX(), (double)pos.getY(), (double)pos.getZ()), Function.identity()));
+ // Paper start - Perf: remove streams and optimize collection
+ List<Map.Entry<Target, BlockPos>> map = Lists.newArrayList();
+ for (BlockPos pos : positions) {
@@ -56,7 +56,7 @@ index 3e27c9a74c38f11a436df8cd413f9f5f16fd8c3e..c4d6b145d54aaf415dd4b08811c02425
int i = 0;
- Set<Target> set3 = Sets.newHashSetWithExpectedSize(set.size());
+ List<Map.Entry<Target, BlockPos>> entryList = Lists.newArrayListWithExpectedSize(positions.size()); // Paper - optimize collection
- int j = (int)(this.maxVisitedNodes * rangeMultiplier);
+ int j = (int)((float)this.maxVisitedNodes * rangeMultiplier);
while (!this.openSet.isEmpty()) {
@@ -69,14 +74,18 @@ public class PathFinder {
@@ -64,11 +64,12 @@ index 3e27c9a74c38f11a436df8cd413f9f5f16fd8c3e..c4d6b145d54aaf415dd4b08811c02425
node.closed = true;
- for (Target target : set) {
+- if (node.distanceManhattan(target) <= (float)distance) {
+ // Paper start - optimize collection
+ for (int i1 = 0; i1 < positions.size(); i1++) {
+ final Map.Entry<Target, BlockPos> entry = positions.get(i1);
+ Target target = entry.getKey();
- if (node.distanceManhattan(target) <= distance) {
++ if (node.distanceManhattan(target) <= distance) {
target.setReached();
- set3.add(target);
+ entryList.add(entry);