Compare commits
33
Commits
bot-system
...
benchmark
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ce574266f | ||
|
|
dcb93dab50 | ||
|
|
f8c0b4c1c1 | ||
|
|
c41f65d4f6 | ||
|
|
54811fb643 | ||
|
|
92442dcdb9 | ||
|
|
68af1f3bb3 | ||
|
|
a796e9c047 | ||
|
|
2c32cadf18 | ||
|
|
32cd519bcf | ||
|
|
88908d8776 | ||
|
|
79bd26968a | ||
|
|
2d288c7a47 | ||
|
|
2c46458bc1 | ||
|
|
9c37414e50 | ||
|
|
fb667c3b4d | ||
|
|
da07b63e0a | ||
|
|
1fe262929e | ||
|
|
0ee93aea23 | ||
|
|
836b41a3aa | ||
|
|
c370461a24 | ||
|
|
a753fe5df9 | ||
|
|
27aeba3f8b | ||
|
|
141a9f92cb | ||
|
|
5e4f0b47c5 | ||
|
|
d0a88987a8 | ||
|
|
9cb199d40a | ||
|
|
a1d218b37a | ||
|
|
7ae1a9f6e4 | ||
|
|
fd74fcabc0 | ||
|
|
4da155c0ed | ||
|
|
7a3f7f9a9e | ||
|
|
1212d34f91 |
@@ -35,6 +35,15 @@ public final class BetterBlockPos extends BlockPos {
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int z;
|
||||
public static long numCreated;
|
||||
|
||||
static {
|
||||
numCreated = 0;
|
||||
}
|
||||
|
||||
{
|
||||
numCreated++;
|
||||
}
|
||||
|
||||
public BetterBlockPos(int x, int y, int z) {
|
||||
super(x, y, z);
|
||||
|
||||
@@ -25,11 +25,15 @@ import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.pathing.calc.openset.BinaryHeapOpenSet;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.Moves;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.pathing.BetterWorldBorder;
|
||||
import baritone.utils.pathing.Favoring;
|
||||
import baritone.utils.pathing.MutableMoveResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -79,6 +83,30 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
||||
int timeCheckInterval = 1 << 6;
|
||||
int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior
|
||||
boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get();
|
||||
|
||||
long[] timeConsumed = new long[Moves.values().length];
|
||||
int[] count = new int[Moves.values().length];
|
||||
int[] stateLookup = new int[Moves.values().length];
|
||||
long[] posCreation = new long[Moves.values().length];
|
||||
long heapRemove = 0;
|
||||
int heapRemoveCount = 0;
|
||||
long heapAdd = 0;
|
||||
int heapAddCount = 0;
|
||||
long heapUpdate = 0;
|
||||
int heapUpdateCount = 0;
|
||||
|
||||
long chunk = 0;
|
||||
int chunkCount = 0;
|
||||
|
||||
long goalCheck = 0;
|
||||
int goalCheckCount = 0;
|
||||
|
||||
long getNode = 0;
|
||||
int getNodeCount = 0;
|
||||
int startVal = BlockStateInterface.numTimesChunkSucceeded;
|
||||
int startVal2 = BlockStateInterface.numBlockStateLookups;
|
||||
long startVal3 = BetterBlockPos.numCreated;
|
||||
|
||||
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && !cancelRequested) {
|
||||
if ((numNodes & (timeCheckInterval - 1)) == 0) { // only call this once every 64 nodes (about half a millisecond)
|
||||
long now = System.currentTimeMillis(); // since nanoTime is slow on windows (takes many microseconds)
|
||||
@@ -92,14 +120,21 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
}
|
||||
long before = System.nanoTime();
|
||||
PathNode currentNode = openSet.removeLowest();
|
||||
long t = System.nanoTime();
|
||||
heapRemove += t - before;
|
||||
heapRemoveCount++;
|
||||
mostRecentConsidered = currentNode;
|
||||
numNodes++;
|
||||
if (goal.isInGoal(currentNode.x, currentNode.y, currentNode.z)) {
|
||||
logDebug("Took " + (System.currentTimeMillis() - startTime) + "ms, " + numMovementsConsidered + " movements considered");
|
||||
return Optional.of(new Path(startNode, currentNode, numNodes, goal, calcContext));
|
||||
}
|
||||
goalCheck += System.nanoTime() - t;
|
||||
goalCheckCount++;
|
||||
for (Moves moves : Moves.values()) {
|
||||
long s = System.nanoTime();
|
||||
int newX = currentNode.x + moves.xOffset;
|
||||
int newZ = currentNode.z + moves.zOffset;
|
||||
if ((newX >> 4 != currentNode.x >> 4 || newZ >> 4 != currentNode.z >> 4) && !calcContext.isLoaded(newX, newZ)) {
|
||||
@@ -107,6 +142,9 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
||||
if (!moves.dynamicXZ) { // only increment the counter if the movement would have gone out of bounds guaranteed
|
||||
numEmptyChunk++;
|
||||
}
|
||||
long costStart = System.nanoTime();
|
||||
chunk += costStart - s;
|
||||
chunkCount++;
|
||||
continue;
|
||||
}
|
||||
if (!moves.dynamicXZ && !worldBorder.entirelyContains(newX, newZ)) {
|
||||
@@ -115,8 +153,19 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
||||
if (currentNode.y + moves.yOffset > 256 || currentNode.y + moves.yOffset < 0) {
|
||||
continue;
|
||||
}
|
||||
long costStart = System.nanoTime();
|
||||
chunk += costStart - s;
|
||||
chunkCount++;
|
||||
// TODO cache cost
|
||||
int numLookupsBefore = BlockStateInterface.numBlockStateLookups;
|
||||
long numCreatedBefore = BetterBlockPos.numCreated;
|
||||
res.reset();
|
||||
moves.apply(calcContext, currentNode.x, currentNode.y, currentNode.z, res);
|
||||
long costEnd = System.nanoTime();
|
||||
stateLookup[moves.ordinal()] += BlockStateInterface.numBlockStateLookups - numLookupsBefore;
|
||||
posCreation[moves.ordinal()] += BetterBlockPos.numCreated - numCreatedBefore;
|
||||
timeConsumed[moves.ordinal()] += costEnd - costStart;
|
||||
count[moves.ordinal()]++;
|
||||
numMovementsConsidered++;
|
||||
double actionCost = res.cost;
|
||||
if (actionCost >= ActionCosts.COST_INF) {
|
||||
@@ -140,7 +189,10 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
||||
// see issue #18
|
||||
actionCost *= favored.calculate(hashCode);
|
||||
}
|
||||
long st = System.nanoTime();
|
||||
PathNode neighbor = getNodeAtPosition(res.x, res.y, res.z, hashCode);
|
||||
getNode += System.nanoTime() - st;
|
||||
getNodeCount++;
|
||||
double tentativeCost = currentNode.cost + actionCost;
|
||||
if (tentativeCost < neighbor.cost) {
|
||||
double improvementBy = neighbor.cost - tentativeCost;
|
||||
@@ -155,9 +207,15 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
||||
neighbor.cost = tentativeCost;
|
||||
neighbor.combinedCost = tentativeCost + neighbor.estimatedCostToGoal;
|
||||
if (neighbor.isOpen()) {
|
||||
long bef = System.nanoTime();
|
||||
openSet.update(neighbor);
|
||||
heapUpdate += System.nanoTime() - bef;
|
||||
heapUpdateCount++;
|
||||
} else {
|
||||
long bef = System.nanoTime();
|
||||
openSet.insert(neighbor);//dont double count, dont insert into open set if it's already there
|
||||
heapAdd += System.nanoTime() - bef;
|
||||
heapAddCount++;
|
||||
}
|
||||
for (int i = 0; i < bestSoFar.length; i++) {
|
||||
double heuristic = neighbor.estimatedCostToGoal + neighbor.cost / COEFFICIENTS[i];
|
||||
@@ -175,6 +233,36 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
||||
}
|
||||
}
|
||||
}
|
||||
int numBlockState = BlockStateInterface.numBlockStateLookups - startVal2;
|
||||
int numSucc = BlockStateInterface.numTimesChunkSucceeded - startVal;
|
||||
long numSuccc = BetterBlockPos.numCreated - startVal3;
|
||||
|
||||
long totalAccountedTimeMS = 0;
|
||||
totalAccountedTimeMS += heapRemove / 1000000;
|
||||
totalAccountedTimeMS += heapAdd / 1000000;
|
||||
totalAccountedTimeMS += heapUpdate / 1000000;
|
||||
totalAccountedTimeMS += chunk / 1000000;
|
||||
totalAccountedTimeMS += getNode / 1000000;
|
||||
totalAccountedTimeMS += goalCheck / 1000000;
|
||||
System.out.println("Out of " + numBlockState + " block state lookups, " + numSucc + " were in the same chunk as the previous and could be cached");
|
||||
System.out.println("Instantiated " + numSuccc + " BetterBlockPos objects");
|
||||
System.out.println("Remove " + (heapRemove / heapRemoveCount) + " " + heapRemove / 1000000 + "ms " + heapRemoveCount);
|
||||
System.out.println("Add " + (heapAdd / heapAddCount) + " " + heapAdd / 1000000 + "ms " + heapAddCount);
|
||||
System.out.println("Update " + (heapUpdate / heapUpdateCount) + " " + heapUpdate / 1000000 + "ms " + heapUpdateCount);
|
||||
System.out.println("Chunk " + (chunk / chunkCount) + " " + chunk / 1000000 + "ms " + chunkCount);
|
||||
System.out.println("GetNode " + (getNode / getNodeCount) + " " + getNode / 1000000 + "ms " + getNodeCount);
|
||||
System.out.println("GoalCheck " + (goalCheck / goalCheckCount) + " " + goalCheck / 1000000 + "ms " + goalCheckCount);
|
||||
ArrayList<Moves> moves = new ArrayList<>(Arrays.asList(Moves.values()));
|
||||
moves.sort(Comparator.comparingLong(k -> timeConsumed[k.ordinal()] / count[k.ordinal()]));
|
||||
for (Moves move : moves) {
|
||||
int num = count[move.ordinal()];
|
||||
long nanoTime = timeConsumed[move.ordinal()];
|
||||
totalAccountedTimeMS += nanoTime / 1000000;
|
||||
System.out.println(nanoTime / num + " " + move + " " + nanoTime / 1000000 + "ms " + num);
|
||||
System.out.println(stateLookup[move.ordinal()] / num + " " + stateLookup[move.ordinal()]);
|
||||
System.out.println(posCreation[move.ordinal()] / num + " " + posCreation[move.ordinal()]);
|
||||
}
|
||||
System.out.println("Total accounted time: " + totalAccountedTimeMS);
|
||||
if (cancelRequested) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -40,9 +40,10 @@ import net.minecraft.world.chunk.Chunk;
|
||||
*/
|
||||
public class BlockStateInterface {
|
||||
|
||||
public static int numBlockStateLookups = 0;
|
||||
public static int numTimesChunkSucceeded = 0;
|
||||
private final Long2ObjectMap<Chunk> loadedChunks;
|
||||
private final WorldData worldData;
|
||||
|
||||
private Chunk prev = null;
|
||||
private CachedRegion prevCached = null;
|
||||
|
||||
@@ -91,7 +92,7 @@ public class BlockStateInterface {
|
||||
}
|
||||
|
||||
public IBlockState get0(int x, int y, int z) { // Mickey resigned
|
||||
|
||||
numBlockStateLookups++;
|
||||
// Invalid vertical position
|
||||
if (y < 0 || y >= 256) {
|
||||
return AIR;
|
||||
@@ -106,6 +107,7 @@ public class BlockStateInterface {
|
||||
// which is a Long2ObjectOpenHashMap.get
|
||||
// see issue #113
|
||||
if (cached != null && cached.x == x >> 4 && cached.z == z >> 4) {
|
||||
numTimesChunkSucceeded++;
|
||||
return cached.getBlockState(x, y, z);
|
||||
}
|
||||
Chunk chunk = loadedChunks.get(ChunkPos.asLong(x >> 4, z >> 4));
|
||||
|
||||
Reference in New Issue
Block a user