testserver/removed/1.14/0248-Avoid-Chunk-Lookups-fo...

84 lines
4.0 KiB
Diff
Raw Normal View History

2019-05-14 02:20:58 +00:00
From 4360aea0767807d156608cd70a55eaa2b2eacf1d Mon Sep 17 00:00:00 2001
2019-04-30 01:20:24 +00:00
From: Aikar <aikar@aikar.co>
Date: Wed, 4 Jul 2018 03:39:51 -0400
Subject: [PATCH] Avoid Chunk Lookups for Entity/TileEntity Current Chunk
SPECIAL 1.14.1 NOTE:
This patch caused a memory leak since the tile entity's chunk was set to null
before it was removed. Ensure this issue is resolved!
2019-04-30 01:20:24 +00:00
In many places where we simply want the current chunk the entity
is in, instead of doing a hashmap lookup for it, we now have access
to the object directly on the Entity/TileEntity object we can directly grab.
Use that local value instead to reduce lookups in many hot places.
2019-04-30 01:20:24 +00:00
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2019-05-14 02:20:58 +00:00
index e3de63489..0e9530ea5 100644
2019-04-30 01:20:24 +00:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -762,7 +762,8 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
2019-04-30 01:20:24 +00:00
if (!tileentity.isRemoved() && tileentity.hasWorld()) {
BlockPosition blockposition = tileentity.getPosition();
2019-05-14 02:20:58 +00:00
- if (this.chunkProvider.a(blockposition) && this.getWorldBorder().a(blockposition)) {
2019-04-30 01:20:24 +00:00
+ Chunk currentChunk = tileentity.getCurrentChunk(); // Paper
+ if (currentChunk != null && this.getWorldBorder().a(blockposition)) { // Paper
try {
gameprofilerfiller.a(() -> {
return String.valueOf(TileEntityTypes.a(tileentity.q()));
2019-05-14 02:20:58 +00:00
@@ -801,7 +802,7 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
2019-04-30 01:20:24 +00:00
this.tileEntityListTick.remove(tileTickPosition--);
// Spigot end
//this.tileEntityList.remove(tileentity); // Paper - remove unused list
- if (this.isLoaded(tileentity.getPosition())) {
+ if (tileentity.getCurrentChunk() != null ) { // Paper - avoid lookups
this.getChunkAtWorldCoords(tileentity.getPosition()).removeTileEntity(tileentity.getPosition());
}
}
2019-05-14 02:20:58 +00:00
@@ -822,8 +823,9 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
2019-04-30 01:20:24 +00:00
}
// CraftBukkit end */
- if (this.isLoaded(tileentity1.getPosition())) {
- Chunk chunk = this.getChunkAtWorldCoords(tileentity1.getPosition());
+ Chunk chunk = tileentity1.getCurrentChunk(); // Paper
+ if (chunk != null) { // Paper
+ //Chunk chunk = this.getChunkAtWorldCoords(tileentity1.getPosition()); // Paper
IBlockData iblockdata = chunk.getType(tileentity1.getPosition());
chunk.setTileEntity(tileentity1.getPosition(), tileentity1);
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
2019-05-14 02:20:58 +00:00
index 067379252..340460a33 100644
2019-04-30 01:20:24 +00:00
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
2019-05-14 02:20:58 +00:00
@@ -1061,7 +1061,7 @@ public class WorldServer extends World {
2019-04-30 01:20:24 +00:00
}
this.entitiesByUUID.remove(entity.getUniqueID());
- this.getChunkProvider().removeEntity(entity);
2019-05-07 13:50:02 +00:00
+ this.getChunkProvider().removeEntity(entity); // Paper
2019-04-30 01:20:24 +00:00
if (entity instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entity;
2019-05-14 02:20:58 +00:00
@@ -1121,9 +1121,12 @@ public class WorldServer extends World {
2019-04-30 01:20:24 +00:00
}
private void removeEntityFromChunk(Entity entity) {
- IChunkAccess ichunkaccess = this.getChunkAt(entity.chunkX, entity.chunkZ, ChunkStatus.FULL, false);
+ // Paper start
+ if (!entity.inChunk) return;
+ IChunkAccess ichunkaccess = this.getChunkIfLoaded(entity.chunkX, entity.chunkZ);
+ // Paper start
- if (ichunkaccess instanceof Chunk) {
+ if (ichunkaccess != null) {
((Chunk) ichunkaccess).b(entity);
}
--
2.21.0