mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-02 17:32:03 +01:00
Reduce allocation rate for checkBlock
Use ObjectOpenHashSet instead of HashSet Remove unnecessary chunkToSave modification
This commit is contained in:
parent
3acabf7aa9
commit
87abd1cde2
2 changed files with 6 additions and 31 deletions
|
@ -15713,17 +15713,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
this.theLightEngine.relightChunks(chunks, (ChunkPos chunkPos) -> {
|
this.theLightEngine.relightChunks(chunks, (ChunkPos chunkPos) -> {
|
||||||
chunkLightCallback.accept(chunkPos);
|
chunkLightCallback.accept(chunkPos);
|
||||||
((java.util.concurrent.Executor)((ServerLevel)this.theLightEngine.getWorld()).getChunkSource().mainThreadProcessor).execute(() -> {
|
((java.util.concurrent.Executor)((ServerLevel)this.theLightEngine.getWorld()).getChunkSource().mainThreadProcessor).execute(() -> {
|
||||||
@@ -0,0 +0,0 @@ public class ThreadedLevelLightEngine extends LevelLightEngine implements AutoCl
|
|
||||||
for (int dz = -1; dz <= 1; ++dz) {
|
|
||||||
ChunkHolder neighbour = world.getChunkSource().chunkMap.getUpdatingChunkIfPresent(CoordinateUtils.getChunkKey(dx + chunkX, dz + chunkZ));
|
|
||||||
if (neighbour != null) {
|
|
||||||
- neighbour.chunkToSave = neighbour.chunkToSave.thenCombine(updateFuture, (final ChunkAccess curr, final Void ignore) -> {
|
|
||||||
- return curr;
|
|
||||||
- });
|
|
||||||
+ // Paper - rewrite chunk system - not needed, light ticket will keep these chunks loaded
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +0,0 @@ public class ThreadedLevelLightEngine extends LevelLightEngine implements AutoCl
|
@@ -0,0 +0,0 @@ public class ThreadedLevelLightEngine extends LevelLightEngine implements AutoCl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3051,6 +3051,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
|
+import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
|
||||||
+import it.unimi.dsi.fastutil.shorts.ShortCollection;
|
+import it.unimi.dsi.fastutil.shorts.ShortCollection;
|
||||||
+import it.unimi.dsi.fastutil.shorts.ShortOpenHashSet;
|
+import it.unimi.dsi.fastutil.shorts.ShortOpenHashSet;
|
||||||
|
+import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
+import net.minecraft.core.BlockPos;
|
+import net.minecraft.core.BlockPos;
|
||||||
+import net.minecraft.core.SectionPos;
|
+import net.minecraft.core.SectionPos;
|
||||||
+import net.minecraft.server.level.ServerChunkCache;
|
+import net.minecraft.server.level.ServerChunkCache;
|
||||||
|
@ -3067,7 +3068,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+import net.minecraft.world.level.lighting.LevelLightEngine;
|
+import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||||
+import java.util.ArrayDeque;
|
+import java.util.ArrayDeque;
|
||||||
+import java.util.ArrayList;
|
+import java.util.ArrayList;
|
||||||
+import java.util.HashSet;
|
|
||||||
+import java.util.List;
|
+import java.util.List;
|
||||||
+import java.util.Set;
|
+import java.util.Set;
|
||||||
+import java.util.concurrent.CompletableFuture;
|
+import java.util.concurrent.CompletableFuture;
|
||||||
|
@ -3693,7 +3693,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+
|
+
|
||||||
+ protected static final class ChunkTasks {
|
+ protected static final class ChunkTasks {
|
||||||
+
|
+
|
||||||
+ public final Set<BlockPos> changedPositions = new HashSet<>();
|
+ public final Set<BlockPos> changedPositions = new ObjectOpenHashSet<>();
|
||||||
+ public Boolean[] changedSectionSet;
|
+ public Boolean[] changedSectionSet;
|
||||||
+ public ShortOpenHashSet queuedEdgeChecksSky;
|
+ public ShortOpenHashSet queuedEdgeChecksSky;
|
||||||
+ public ShortOpenHashSet queuedEdgeChecksBlock;
|
+ public ShortOpenHashSet queuedEdgeChecksBlock;
|
||||||
|
@ -4554,8 +4554,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ // Paper start - replace light engine impl
|
+ // Paper start - replace light engine impl
|
||||||
+ protected final ChunkAccess getChunk(final int chunkX, final int chunkZ) {
|
+ protected final ChunkAccess getChunk(final int chunkX, final int chunkZ) {
|
||||||
+ return ((ServerLevel)this.theLightEngine.getWorld()).getChunkSource().getChunkAtImmediately(chunkX, chunkZ);
|
+ return ((ServerLevel)this.theLightEngine.getWorld()).getChunkSource().getChunkAtImmediately(chunkX, chunkZ);
|
||||||
+ }
|
}
|
||||||
+
|
|
||||||
+ protected long relightCounter;
|
+ protected long relightCounter;
|
||||||
+
|
+
|
||||||
+ public int relight(java.util.Set<ChunkPos> chunks_param,
|
+ public int relight(java.util.Set<ChunkPos> chunks_param,
|
||||||
|
@ -4643,20 +4643,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ world.getChunkSource().addRegionTicket(ca.spottedleaf.starlight.common.light.StarLightInterface.CHUNK_WORK_TICKET, pos, 0, pos);
|
+ world.getChunkSource().addRegionTicket(ca.spottedleaf.starlight.common.light.StarLightInterface.CHUNK_WORK_TICKET, pos, 0, pos);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ // append future to this chunk and 1 radius neighbours chunk save futures
|
|
||||||
+ // this prevents us from saving the world without first waiting for the light engine
|
|
||||||
+
|
|
||||||
+ for (int dx = -1; dx <= 1; ++dx) {
|
|
||||||
+ for (int dz = -1; dz <= 1; ++dz) {
|
|
||||||
+ ChunkHolder neighbour = world.getChunkSource().chunkMap.getUpdatingChunkIfPresent(CoordinateUtils.getChunkKey(dx + chunkX, dz + chunkZ));
|
|
||||||
+ if (neighbour != null) {
|
|
||||||
+ neighbour.chunkToSave = neighbour.chunkToSave.thenCombine(updateFuture, (final ChunkAccess curr, final Void ignore) -> {
|
|
||||||
+ return curr;
|
|
||||||
+ });
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ updateFuture.thenAcceptAsync((final Void ignore) -> {
|
+ updateFuture.thenAcceptAsync((final Void ignore) -> {
|
||||||
+ final int newReferences = this.chunksBeingWorkedOn.get(key);
|
+ final int newReferences = this.chunksBeingWorkedOn.get(key);
|
||||||
+ if (newReferences == 1) {
|
+ if (newReferences == 1) {
|
||||||
|
@ -4677,8 +4663,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ public boolean hasLightWork() {
|
+ public boolean hasLightWork() {
|
||||||
+ // route to new light engine
|
+ // route to new light engine
|
||||||
+ return this.theLightEngine.hasUpdates();
|
+ return this.theLightEngine.hasUpdates();
|
||||||
}
|
+ }
|
||||||
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public LayerLightEventListener getLayerListener(final LightLayer lightType) {
|
+ public LayerLightEventListener getLayerListener(final LightLayer lightType) {
|
||||||
+ return lightType == LightLayer.BLOCK ? this.theLightEngine.getBlockReader() : this.theLightEngine.getSkyReader();
|
+ return lightType == LightLayer.BLOCK ? this.theLightEngine.getBlockReader() : this.theLightEngine.getSkyReader();
|
||||||
|
|
Loading…
Reference in a new issue