way more bench checks

This commit is contained in:
leijurv
2018-08-28 21:10:50 -07:00
parent 4da155c0ed
commit fd74fcabc0
@@ -18,6 +18,7 @@
package baritone.pathing.calc; package baritone.pathing.calc;
import baritone.Baritone; import baritone.Baritone;
import baritone.chunk.CachedWorld;
import baritone.chunk.WorldProvider; import baritone.chunk.WorldProvider;
import baritone.pathing.calc.openset.BinaryHeapOpenSet; import baritone.pathing.calc.openset.BinaryHeapOpenSet;
import baritone.pathing.calc.openset.IOpenSet; import baritone.pathing.calc.openset.IOpenSet;
@@ -78,8 +79,24 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior
double favorCoeff = Baritone.settings().backtrackCostFavoringCoefficient.get(); double favorCoeff = Baritone.settings().backtrackCostFavoringCoefficient.get();
boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get(); boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get();
CachedWorld world=Optional.ofNullable(WorldProvider.INSTANCE.getCurrentWorld()).map(w->w.cache).orElse(null);
HashMap<Class<? extends Movement>, Long> timeConsumed = new HashMap<>(); HashMap<Class<? extends Movement>, Long> timeConsumed = new HashMap<>();
HashMap<Class<? extends Movement>, Integer> count = new HashMap<>(); HashMap<Class<? extends Movement>, Integer> count = new HashMap<>();
long heapRemove=0;
int heapRemoveCount=0;
long heapAdd=0;
int heapAddCount=0;
long heapUpdate=0;
int heapUpdateCount=0;
long construction=0;
int constructionCount=0;
long chunk=0;
int chunkCount=0;
long chunk2=0;
int chunkCount2=0;
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.currentTimeMillis() < timeoutTime && !cancelRequested) { while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.currentTimeMillis() < timeoutTime && !cancelRequested) {
if (slowPath) { if (slowPath) {
try { try {
@@ -87,7 +104,10 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
} }
} }
long before=System.nanoTime();
PathNode currentNode = openSet.removeLowest(); PathNode currentNode = openSet.removeLowest();
heapRemove+=System.nanoTime()-before;
heapRemoveCount++;
currentNode.isOpen = false; currentNode.isOpen = false;
mostRecentConsidered = currentNode; mostRecentConsidered = currentNode;
BetterBlockPos currentNodePos = currentNode.pos; BetterBlockPos currentNodePos = currentNode.pos;
@@ -100,27 +120,35 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
currentlyRunning = null; currentlyRunning = null;
return Optional.of(new Path(startNode, currentNode, numNodes)); return Optional.of(new Path(startNode, currentNode, numNodes));
} }
//long constructStart = System.nanoTime(); long constructStart = System.nanoTime();
Movement[] possibleMovements = getConnectedPositions(currentNodePos, calcContext);//movement that we could take that start at currentNodePos, in random order Movement[] possibleMovements = getConnectedPositions(currentNodePos, calcContext);//movement that we could take that start at currentNodePos, in random order
shuffle(possibleMovements); shuffle(possibleMovements);
//long constructEnd = System.nanoTime(); long constructEnd = System.nanoTime();
construction+=constructEnd-constructStart;
constructionCount++;
//System.out.println(constructEnd - constructStart); //System.out.println(constructEnd - constructStart);
for (Movement movementToGetToNeighbor : possibleMovements) { for (Movement movementToGetToNeighbor : possibleMovements) {
if (movementToGetToNeighbor == null) { if (movementToGetToNeighbor == null) {
continue; continue;
} }
BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest(); BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest();
long s=System.nanoTime();
boolean isPositionCached = false; boolean isPositionCached = false;
if (WorldProvider.INSTANCE.getCurrentWorld() != null) { if (world != null) {
if (WorldProvider.INSTANCE.getCurrentWorld().cache.getBlock(dest) != null) { if (world.getBlock(dest) != null) {
isPositionCached = true; isPositionCached = true;
} }
} }
long k=System.nanoTime();
chunk2+=k-s;
chunkCount2++;
if (!isPositionCached && Minecraft.getMinecraft().world.getChunk(dest) instanceof EmptyChunk) { if (!isPositionCached && Minecraft.getMinecraft().world.getChunk(dest) instanceof EmptyChunk) {
numEmptyChunk++; numEmptyChunk++;
continue; continue;
} }
long costStart = System.nanoTime(); long costStart = System.nanoTime();
chunk+=costStart-k;
chunkCount++;
// TODO cache cost // TODO cache cost
double actionCost = movementToGetToNeighbor.getCost(calcContext); double actionCost = movementToGetToNeighbor.getCost(calcContext);
long costEnd = System.nanoTime(); long costEnd = System.nanoTime();
@@ -157,9 +185,15 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
neighbor.cost = tentativeCost; neighbor.cost = tentativeCost;
neighbor.combinedCost = tentativeCost + neighbor.estimatedCostToGoal; neighbor.combinedCost = tentativeCost + neighbor.estimatedCostToGoal;
if (neighbor.isOpen) { if (neighbor.isOpen) {
long bef=System.nanoTime();
openSet.update(neighbor); openSet.update(neighbor);
heapUpdate+=System.nanoTime()-bef;
heapUpdateCount++;
} else { } else {
long bef=System.nanoTime();
openSet.insert(neighbor);//dont double count, dont insert into open set if it's already there openSet.insert(neighbor);//dont double count, dont insert into open set if it's already there
heapAdd+=System.nanoTime()-bef;
heapAddCount++;
neighbor.isOpen = true; neighbor.isOpen = true;
} }
for (int i = 0; i < bestSoFar.length; i++) { for (int i = 0; i < bestSoFar.length; i++) {
@@ -172,12 +206,18 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
} }
} }
} }
System.out.println("Remove "+(heapRemove/heapRemoveCount)+" "+heapRemove/1000000+" "+heapRemoveCount);
System.out.println("Add "+(heapAdd/heapAddCount)+" "+heapAdd/1000000+" "+heapAddCount);
System.out.println("Update "+(heapUpdate/heapUpdateCount)+" "+heapUpdate/1000000+" "+heapUpdateCount);
System.out.println("Construction "+(construction/constructionCount)+" "+construction/1000000+" "+constructionCount);
System.out.println("EmptyChunk "+(chunk/chunkCount)+" "+chunk/1000000+" "+chunkCount);
System.out.println("CachedChunk "+(chunk2/chunkCount2)+" "+chunk2/1000000+" "+chunkCount2);
ArrayList<Class<? extends Movement>> klasses = new ArrayList<>(count.keySet()); ArrayList<Class<? extends Movement>> klasses = new ArrayList<>(count.keySet());
klasses.sort(Comparator.comparingLong(k -> timeConsumed.get(k) / count.get(k))); klasses.sort(Comparator.comparingLong(k -> timeConsumed.get(k) / count.get(k)));
for (Class<? extends Movement> klass : klasses) { for (Class<? extends Movement> klass : klasses) {
int num = count.get(klass); int num = count.get(klass);
long nanoTime = timeConsumed.get(klass); long nanoTime = timeConsumed.get(klass);
System.out.println(nanoTime / num + " " + klass + " " + nanoTime + " " + num); System.out.println(nanoTime / num + " " + klass + " " + nanoTime/1000000 + "ms " + num);
} }
if (cancelRequested) { if (cancelRequested) {
currentlyRunning = null; currentlyRunning = null;