more headless speed

This commit is contained in:
Julian Krings 2024-08-23 15:05:45 +02:00
parent 3bffe4cc7e
commit b1e87afc93
2 changed files with 12 additions and 5 deletions

View File

@ -33,7 +33,7 @@ public class SyncChunkDataHunkHolder extends ArrayHunk<BlockData> {
} }
public void apply() { public void apply() {
for (int i = 0; i < getHeight(); i++) { for (int i = getHeight()-1; i >= 0; i--) {
for (int j = 0; j < getWidth(); j++) { for (int j = 0; j < getWidth(); j++) {
for (int k = 0; k < getDepth(); k++) { for (int k = 0; k < getDepth(); k++) {
BlockData b = super.getRaw(j, i, k); BlockData b = super.getRaw(j, i, k);

View File

@ -45,15 +45,20 @@ public final class RegionFileStorage implements AutoCloseable {
this.sync = sync; this.sync = sync;
} }
public synchronized RegionFile getRegionFile(ChunkPos chunkPos, boolean existingOnly) throws IOException { public RegionFile getRegionFile(ChunkPos chunkPos, boolean existingOnly) throws IOException {
long id = ChunkPos.asLong(chunkPos.getRegionX(), chunkPos.getRegionZ()); long id = ChunkPos.asLong(chunkPos.getRegionX(), chunkPos.getRegionZ());
RegionFile regionFile = this.regionCache.getAndMoveToFirst(id); RegionFile regionFile;
synchronized (this.regionCache) {
regionFile = this.regionCache.getAndMoveToFirst(id);
}
if (regionFile != null) { if (regionFile != null) {
return regionFile; return regionFile;
} else { } else {
if (this.regionCache.size() >= 256) { if (this.regionCache.size() >= 256) {
synchronized (this.regionCache) {
this.regionCache.removeLast().close(); this.regionCache.removeLast().close();
} }
}
FileUtil.createDirectoriesSafe(this.folder); FileUtil.createDirectoriesSafe(this.folder);
Path path = folder.resolve("r." + chunkPos.getRegionX() + "." + chunkPos.getRegionZ() + ".mca"); Path path = folder.resolve("r." + chunkPos.getRegionX() + "." + chunkPos.getRegionZ() + ".mca");
@ -61,7 +66,9 @@ public final class RegionFileStorage implements AutoCloseable {
return null; return null;
} else { } else {
regionFile = new RegionFile(path, this.folder, this.sync); regionFile = new RegionFile(path, this.folder, this.sync);
synchronized (this.regionCache) {
this.regionCache.putAndMoveToFirst(id, regionFile); this.regionCache.putAndMoveToFirst(id, regionFile);
}
return regionFile; return regionFile;
} }
} }