Compare commits

...

33 Commits

Author SHA1 Message Date
Leijurv 9ce574266f
Merge branch 'master' into benchmark 2019-01-17 12:24:23 -08:00
Leijurv dcb93dab50
Merge branch 'master' into benchmark 2018-11-23 13:42:20 -08:00
Leijurv f8c0b4c1c1
Merge branch 'master' into benchmark 2018-11-13 13:30:51 -08:00
Leijurv c41f65d4f6
clean up benchmark branch 2018-09-27 11:38:32 -07:00
Leijurv 54811fb643
merge 2018-09-27 10:22:37 -07:00
Leijurv 92442dcdb9
total accounted time 2018-09-26 13:58:11 -07:00
Leijurv 68af1f3bb3
Merge branch 'master' into benchmark 2018-09-26 13:46:29 -07:00
Leijurv a796e9c047
merge 2018-09-26 13:45:00 -07:00
Leijurv 2c32cadf18
count BetterBlockPos 2018-09-22 08:55:46 -07:00
Leijurv 32cd519bcf
merge 2018-09-22 08:51:03 -07:00
Leijurv 88908d8776
more better block pos 2018-09-22 08:47:02 -07:00
Leijurv 79bd26968a
count betterblockpos instantiation 2018-09-21 22:10:25 -07:00
Leijurv 2d288c7a47
Merge branch 'master' into benchmark 2018-09-21 21:58:26 -07:00
Leijurv 2c46458bc1
merge 2018-09-11 13:57:01 -07:00
Brady 9c37414e50
Merge branch 'master' into benchmark 2018-09-07 19:31:01 -05:00
Leijurv fb667c3b4d
merge 2018-09-04 15:41:35 -07:00
Leijurv da07b63e0a
measure 2018-08-31 12:57:38 -07:00
Leijurv 1fe262929e
forgot print 2018-08-31 12:04:55 -07:00
Leijurv 0ee93aea23
cache chunk in BlockStateInterface 2018-08-31 11:51:43 -07:00
Leijurv 836b41a3aa
num lookups check 2018-08-31 11:51:08 -07:00
Leijurv c370461a24
merge 2018-08-31 11:45:45 -07:00
Leijurv a753fe5df9
bench the whole loop 2018-08-29 14:46:58 -07:00
Leijurv 27aeba3f8b
Merge branch 'master' into benchmark 2018-08-29 14:16:32 -07:00
Leijurv 141a9f92cb
node map performance, fixes #107 2018-08-29 13:21:54 -07:00
Leijurv 5e4f0b47c5
merge 2018-08-29 12:24:45 -07:00
leijurv d0a88987a8 format 2018-08-29 07:38:35 -07:00
leijurv 9cb199d40a also bench getnode 2018-08-28 21:31:16 -07:00
leijurv a1d218b37a merge 2018-08-28 21:17:12 -07:00
leijurv 7ae1a9f6e4 3x faster cache check 2018-08-28 21:14:50 -07:00
leijurv fd74fcabc0 way more bench checks 2018-08-28 21:10:56 -07:00
leijurv 4da155c0ed 20% improvement to cached chunk check performance 2018-08-28 21:10:41 -07:00
leijurv 7a3f7f9a9e Merge branch 'master' into benchmark 2018-08-28 20:51:42 -07:00
Leijurv 1212d34f91
rudimentary benchmark 2018-08-28 15:48:36 -07:00
3 changed files with 101 additions and 2 deletions

View File

@ -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);

View File

@ -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();
}

View File

@ -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));