add an early drop out if score is zero
@@ -171,8 +171,9 @@ public void addRelevanceEntity(EntityRef entity, Vector3i distance, ChunkRegionL
} finally {
regionLock.writeLock().unlock();
}
+
StreamSupport.stream(region.getCurrentRegion().spliterator(), false)
-// .sorted(new PositionRelevanceComparator()) <-- this is n^2 cost. not sure why this needs to be sorted like this.
+ .sorted(new PositionRelevanceComparator()) //<-- this is n^2 cost. not sure why this needs to be sorted like this.
.forEach(
pos -> {
Chunk chunk = chunkProvider.getChunk(pos);
@@ -252,11 +253,15 @@ private int regionsDistanceScore(Vector3i chunk) {
regionLock.readLock().lock();
try {
+
for (ChunkRelevanceRegion region : regions.values()) {
int dist = distFromRegion(chunk, region.getCenter());
if (dist < score) {
score = dist;
}
+ if (score == 0) {
+ break;
+ }
}
return score;
} finally {
