Update more feature patches
This commit is contained in:
@@ -15,100 +15,104 @@ Optimize collection by creating a list instead of a set of the key and value.
|
||||
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
|
||||
@@ -0,0 +0,0 @@ public class PathFinder {
|
||||
if (node == null) {
|
||||
|
||||
diff --git a/net/minecraft/world/level/pathfinder/PathFinder.java b/net/minecraft/world/level/pathfinder/PathFinder.java
|
||||
index a6ef296f7af1f784e1f0772947a6cb3519a3bc2a..81de6c1bbef1cafd3036e736dd305fbedc8368c6 100644
|
||||
--- a/net/minecraft/world/level/pathfinder/PathFinder.java
|
||||
+++ b/net/minecraft/world/level/pathfinder/PathFinder.java
|
||||
@@ -43,8 +43,12 @@ public class PathFinder {
|
||||
if (start == null) {
|
||||
return null;
|
||||
} else {
|
||||
- Map<Target, BlockPos> map = positions.stream()
|
||||
- .collect(Collectors.toMap(pos -> this.nodeEvaluator.getTarget((double)pos.getX(), (double)pos.getY(), (double)pos.getZ()), Function.identity()));
|
||||
- Map<Target, BlockPos> map = targetPositions.stream()
|
||||
- .collect(Collectors.toMap(pos -> this.nodeEvaluator.getTarget(pos.getX(), pos.getY(), pos.getZ()), Function.identity()));
|
||||
+ // Paper start - Perf: remove streams and optimize collection
|
||||
+ List<Map.Entry<Target, BlockPos>> map = Lists.newArrayList();
|
||||
+ for (final BlockPos pos : positions) {
|
||||
+ for (BlockPos pos : targetPositions) {
|
||||
+ map.add(new java.util.AbstractMap.SimpleEntry<>(this.nodeEvaluator.getTarget(pos.getX(), pos.getY(), pos.getZ()), pos));
|
||||
+ }
|
||||
+ // Paper end - Perf: remove streams and optimize collection
|
||||
Path path = this.findPath(node, map, followRange, distance, rangeMultiplier);
|
||||
Path path = this.findPath(start, map, maxRange, accuracy, searchDepthMultiplier);
|
||||
this.nodeEvaluator.done();
|
||||
return path;
|
||||
@@ -0,0 +0,0 @@ public class PathFinder {
|
||||
@@ -52,19 +56,19 @@ public class PathFinder {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
- private Path findPath(Node startNode, Map<Target, BlockPos> positions, float followRange, int distance, float rangeMultiplier) {
|
||||
+ // Paper start - Perf: remove streams and optimize collection
|
||||
+ private Path findPath(Node startNode, List<Map.Entry<Target, BlockPos>> positions, float followRange, int distance, float rangeMultiplier) {
|
||||
- private Path findPath(Node node, Map<Target, BlockPos> targetPositions, float maxRange, int accuracy, float searchDepthMultiplier) {
|
||||
+ private Path findPath(Node node, List<Map.Entry<Target, BlockPos>> positions, float maxRange, int accuracy, float searchDepthMultiplier) { // Paper - optimize collection
|
||||
ProfilerFiller profilerFiller = Profiler.get();
|
||||
profilerFiller.push("find_path");
|
||||
profilerFiller.markForCharting(MetricCategory.PATH_FINDING);
|
||||
- Set<Target> set = positions.keySet();
|
||||
+ // Set<Target> set = positions.keySet();
|
||||
startNode.g = 0.0F;
|
||||
- startNode.h = this.getBestH(startNode, set);
|
||||
+ startNode.h = this.getBestH(startNode, positions); // Paper - optimize collection
|
||||
startNode.f = startNode.h;
|
||||
- Set<Target> set = targetPositions.keySet();
|
||||
+ // Set<Target> set = targetPositions.keySet(); // Paper
|
||||
node.g = 0.0F;
|
||||
- node.h = this.getBestH(node, set);
|
||||
+ node.h = this.getBestH(node, positions); // Paper - optimize collection
|
||||
node.f = node.h;
|
||||
this.openSet.clear();
|
||||
this.openSet.insert(startNode);
|
||||
- Set<Node> set2 = ImmutableSet.of();
|
||||
+ // Set<Node> set2 = ImmutableSet.of(); // Paper - unused - diff on change
|
||||
this.openSet.insert(node);
|
||||
- Set<Node> set1 = ImmutableSet.of();
|
||||
+ // Set<Node> set1 = ImmutableSet.of(); // Paper - unused - diff on change
|
||||
int i = 0;
|
||||
- Set<Target> set3 = Sets.newHashSetWithExpectedSize(set.size());
|
||||
- Set<Target> set2 = Sets.newHashSetWithExpectedSize(set.size());
|
||||
+ List<Map.Entry<Target, BlockPos>> entryList = Lists.newArrayListWithExpectedSize(positions.size()); // Paper - optimize collection
|
||||
int j = (int)((float)this.maxVisitedNodes * rangeMultiplier);
|
||||
int i1 = (int)(this.maxVisitedNodes * searchDepthMultiplier);
|
||||
|
||||
while (!this.openSet.isEmpty()) {
|
||||
@@ -0,0 +0,0 @@ public class PathFinder {
|
||||
Node node = this.openSet.pop();
|
||||
node.closed = true;
|
||||
@@ -75,14 +79,18 @@ public class PathFinder {
|
||||
Node node1 = this.openSet.pop();
|
||||
node1.closed = true;
|
||||
|
||||
- for (Target target : set) {
|
||||
+ // Paper start - optimize collection
|
||||
+ for (int i1 = 0; i1 < positions.size(); i1++) {
|
||||
+ final Map.Entry<Target, BlockPos> entry = positions.get(i1);
|
||||
+ for (int positionIndex = 0, size = positions.size(); positionIndex < size; positionIndex++) {
|
||||
+ final Map.Entry<Target, BlockPos> entry = positions.get(positionIndex);
|
||||
+ Target target = entry.getKey();
|
||||
if (node.distanceManhattan(target) <= (float)distance) {
|
||||
if (node1.distanceManhattan(target) <= accuracy) {
|
||||
target.setReached();
|
||||
- set3.add(target);
|
||||
- set2.add(target);
|
||||
+ entryList.add(entry);
|
||||
+ // Paper end - Perf: remove streams and optimize collection
|
||||
}
|
||||
}
|
||||
|
||||
- if (!set3.isEmpty()) {
|
||||
- if (!set2.isEmpty()) {
|
||||
+ if (!entryList.isEmpty()) { // Paper - Perf: remove streams and optimize collection; rename
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -0,0 +0,0 @@ public class PathFinder {
|
||||
if (node2.walkedDistance < followRange && (!node2.inOpenSet() || g < node2.g)) {
|
||||
node2.cameFrom = node;
|
||||
node2.g = g;
|
||||
@@ -97,7 +105,7 @@ public class PathFinder {
|
||||
if (node2.walkedDistance < maxRange && (!node2.inOpenSet() || f1 < node2.g)) {
|
||||
node2.cameFrom = node1;
|
||||
node2.g = f1;
|
||||
- node2.h = this.getBestH(node2, set) * 1.5F;
|
||||
+ node2.h = this.getBestH(node2, positions) * 1.5F; // Paper - Perf: remove streams and optimize collection
|
||||
if (node2.inOpenSet()) {
|
||||
this.openSet.changeCost(node2, node2.g + node2.h);
|
||||
} else {
|
||||
@@ -0,0 +0,0 @@ public class PathFinder {
|
||||
@@ -109,25 +117,34 @@ public class PathFinder {
|
||||
}
|
||||
}
|
||||
|
||||
- Optional<Path> optional = !set3.isEmpty()
|
||||
- ? set3.stream().map(node -> this.reconstructPath(node.getBestNode(), positions.get(node), true)).min(Comparator.comparingInt(Path::getNodeCount))
|
||||
- Optional<Path> optional = !set2.isEmpty()
|
||||
- ? set2.stream()
|
||||
- .map(pathfinder -> this.reconstructPath(pathfinder.getBestNode(), targetPositions.get(pathfinder), true))
|
||||
- .min(Comparator.comparingInt(Path::getNodeCount))
|
||||
- : set.stream()
|
||||
- .map(targetx -> this.reconstructPath(targetx.getBestNode(), positions.get(targetx), false))
|
||||
- .map(pathfinder -> this.reconstructPath(pathfinder.getBestNode(), targetPositions.get(pathfinder), false))
|
||||
- .min(Comparator.comparingDouble(Path::getDistToTarget).thenComparingInt(Path::getNodeCount));
|
||||
+ // Paper start - Perf: remove streams and optimize collection
|
||||
+ Path best = null;
|
||||
+ boolean entryListIsEmpty = entryList.isEmpty();
|
||||
+ Comparator<Path> comparator = entryListIsEmpty ? Comparator.comparingInt(Path::getNodeCount)
|
||||
+ Comparator<Path> comparator = entryListIsEmpty
|
||||
+ ? Comparator.comparingInt(Path::getNodeCount)
|
||||
+ : Comparator.comparingDouble(Path::getDistToTarget).thenComparingInt(Path::getNodeCount);
|
||||
+ for (Map.Entry<Target, BlockPos> entry : entryListIsEmpty ? positions : entryList) {
|
||||
+ Path path = this.reconstructPath(entry.getKey().getBestNode(), entry.getValue(), !entryListIsEmpty);
|
||||
+ if (best == null || comparator.compare(path, best) < 0)
|
||||
+ if (best == null || comparator.compare(path, best) < 0) {
|
||||
+ best = path;
|
||||
+ }
|
||||
+ }
|
||||
profilerFiller.pop();
|
||||
- return optional.isEmpty() ? null : optional.get();
|
||||
@@ -116,8 +120,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ // Paper end - Perf: remove streams and optimize collection
|
||||
}
|
||||
|
||||
protected float distance(Node a, Node b) {
|
||||
return a.distanceTo(b);
|
||||
protected float distance(Node first, Node second) {
|
||||
return first.distanceTo(second);
|
||||
}
|
||||
|
||||
- private float getBestH(Node node, Set<Target> targets) {
|
||||
@@ -129,6 +133,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ for (int i = 0, targetsSize = targets.size(); i < targetsSize; i++) {
|
||||
+ final Target target = targets.get(i).getKey();
|
||||
+ // Paper end - Perf: remove streams and optimize collection
|
||||
float g = node.distanceTo(target);
|
||||
target.updateBest(g, node);
|
||||
f = Math.min(g, f);
|
||||
float f1 = node.distanceTo(target);
|
||||
target.updateBest(f1, node);
|
||||
f = Math.min(f1, f);
|
||||
|
||||
Reference in New Issue
Block a user