From 6d1130d2c3eadcfbfa880edb791940cf6b3c5305 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 26 Nov 2018 07:52:00 -0800 Subject: [PATCH] favored lookup performance --- .../java/baritone/behavior/PathingBehavior.java | 13 +++++++++---- .../java/baritone/pathing/calc/AStarPathFinder.java | 7 ++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 1a4b12b9..106f52cc 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -37,12 +37,15 @@ import baritone.pathing.path.CutoffPath; import baritone.pathing.path.PathExecutor; import baritone.utils.Helper; import baritone.utils.PathRenderer; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.EmptyChunk; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Objects; +import java.util.Optional; import java.util.concurrent.LinkedBlockingQueue; -import java.util.stream.Collectors; public final class PathingBehavior extends Behavior implements IPathingBehavior, Helper { @@ -492,9 +495,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, transformed = new GoalXZ(pos.getX(), pos.getZ()); } } - HashSet favoredPositions = null; + LongOpenHashSet favoredPositions = null; if (Baritone.settings().backtrackCostFavoringCoefficient.get() != 1D && previous != null) { - favoredPositions = previous.positions().stream().map(BetterBlockPos::longHash).collect(Collectors.toCollection(HashSet::new)); + LongOpenHashSet tmp = new LongOpenHashSet(); + previous.positions().forEach(pos -> tmp.add(BetterBlockPos.longHash(pos))); + favoredPositions = tmp; } return new AStarPathFinder(start.getX(), start.getY(), start.getZ(), transformed, favoredPositions, context); } diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 989fda55..d7292da7 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -28,6 +28,7 @@ import baritone.pathing.movement.Moves; import baritone.utils.Helper; import baritone.utils.pathing.BetterWorldBorder; import baritone.utils.pathing.MutableMoveResult; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import java.util.HashSet; import java.util.Optional; @@ -39,10 +40,10 @@ import java.util.Optional; */ public final class AStarPathFinder extends AbstractNodeCostSearch implements Helper { - private final HashSet favoredPositions; + private final LongOpenHashSet favoredPositions; private final CalculationContext calcContext; - public AStarPathFinder(int startX, int startY, int startZ, Goal goal, HashSet favoredPositions, CalculationContext context) { + public AStarPathFinder(int startX, int startY, int startZ, Goal goal, LongOpenHashSet favoredPositions, CalculationContext context) { super(startX, startY, startZ, goal, context); this.favoredPositions = favoredPositions; this.calcContext = context; @@ -63,7 +64,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel bestSoFar[i] = startNode; } MutableMoveResult res = new MutableMoveResult(); - HashSet favored = favoredPositions; + LongOpenHashSet favored = favoredPositions; BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world().getWorldBorder()); long startTime = System.nanoTime() / 1000000L; boolean slowPath = Baritone.settings().slowPath.get();