mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
9fa6ba267c
Massive update to light to improve performance and chunk loading/generation. 1) Massive bit packing/unpacking optimizations and inlining. A lot of performance has to do with constant packing and unpacking of bits. We now inline a most bit operations, and re-use base x/y/z bits in many places. This helps with cpu level processing to just do all the math at once instead of having to jump in and out of function calls. This much logic also is likely over the JVM Inline limit for JIT too. 2) Applied a few of JellySquid's Phosphor mod optimizations such as - ensuring we don't notify neighbor chunks when neighbor chunk doesn't need to be notified - reduce hasLight checks in initializing light, and prob some more, they are tagged JellySquid where phosphor influence was used. 3) Optimize hot path accesses to getting updating chunk to have less branching 4) Optimize getBlock accesses to have less branching, and less unpacking 5) Have a separate urgent bucket for chunk light tasks. These tasks will always cut in line over non blocking light tasks. 6) Retain chunk priority while light tasks are enqueued. So if a task comes in at high priority but the queue is full of tasks already at a lower priority, before the task was simply added to the end. Now it can cut in line to the front. this applies for both urgent and non urgent tasks. 7) Buffer non urgent tasks even if queueUpdate is called multiple times to improve efficiency. 8) Fix NPE risk that crashes server in getting nibble data Fixes #3489 Fixes #3363
72 lines
3.3 KiB
Diff
72 lines
3.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Mon, 23 Jul 2018 22:44:23 -0400
|
|
Subject: [PATCH] Add some Debug to Chunk Entity slices
|
|
|
|
If we detect unexpected state, log and try to recover
|
|
|
|
This should hopefully avoid duplicate entities ever being created
|
|
if the entity was to end up in 2 different chunk slices
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
|
index f0a8142b7477fde211b522e3982e614fc94e20f8..9f369f932ca0a63bde246420cfde7949f3e78ca2 100644
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
|
@@ -509,6 +509,25 @@ public class Chunk implements IChunkAccess {
|
|
if (k >= this.entitySlices.length) {
|
|
k = this.entitySlices.length - 1;
|
|
}
|
|
+ // Paper - remove from any old list if its in one
|
|
+ List<Entity> nextSlice = this.entitySlices[k]; // the next list to be added to
|
|
+ List<Entity> currentSlice = entity.entitySlice;
|
|
+ if (nextSlice == currentSlice) {
|
|
+ if (World.DEBUG_ENTITIES) MinecraftServer.LOGGER.warn("Entity was already in this chunk!" + entity, new Throwable());
|
|
+ return; // ??? silly plugins
|
|
+ }
|
|
+ if (currentSlice != null && currentSlice.contains(entity)) {
|
|
+ // Still in an old chunk...
|
|
+ if (World.DEBUG_ENTITIES) MinecraftServer.LOGGER.warn("Entity is still in another chunk!" + entity, new Throwable());
|
|
+ Chunk chunk = entity.getCurrentChunk();
|
|
+ if (chunk != null) {
|
|
+ chunk.removeEntity(entity);
|
|
+ } else {
|
|
+ removeEntity(entity);
|
|
+ }
|
|
+ currentSlice.remove(entity); // Just incase the above did not remove from the previous slice
|
|
+ }
|
|
+ // Paper end
|
|
|
|
if (!entity.inChunk || entity.getCurrentChunk() != this) entityCounts.increment(entity.getMinecraftKeyString()); // Paper
|
|
entity.inChunk = true;
|
|
@@ -518,6 +537,7 @@ public class Chunk implements IChunkAccess {
|
|
entity.chunkZ = this.loc.z;
|
|
this.entities.add(entity); // Paper - per chunk entity list
|
|
this.entitySlices[k].add(entity);
|
|
+ entity.entitySlice = this.entitySlices[k]; // Paper
|
|
this.markDirty(); // Paper
|
|
}
|
|
|
|
@@ -542,6 +562,10 @@ public class Chunk implements IChunkAccess {
|
|
|
|
// Paper start
|
|
if (entity.currentChunk != null && entity.currentChunk.get() == this) entity.setCurrentChunk(null);
|
|
+ if (entitySlices[i] == entity.entitySlice) {
|
|
+ entity.entitySlice = null;
|
|
+ entity.inChunk = false;
|
|
+ }
|
|
if (!this.entitySlices[i].remove(entity)) {
|
|
return;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
|
index 653e6d9a1640bedf08aaa5b436ac93e4cb1cb5b7..84d36ea84e25a701af22900af6cd3099adf6cd54 100644
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
|
@@ -71,6 +71,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
|
}
|
|
}
|
|
};
|
|
+ List<Entity> entitySlice = null;
|
|
// Paper end
|
|
|
|
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
|