Optimize some light chunk access

light calculations repeatedly looks up the same chunk while going
down on the Y access. Pass the chunk to it to skip many round trips
to the map lookup process.

while the gains arent as big since we have last access cache, it
should hopefully avoid many callstacks of depth and improve inlining,
as well as avoids entering a synchronized code block.

The avoiding of entering synchronized section is the main goal here.
This commit is contained in:
Aikar 2018-10-02 21:55:30 -04:00
parent 49f584a14b
commit e45b853e60
No known key found for this signature in database
GPG Key ID: 401ADFC9891FAAFE
2 changed files with 43 additions and 7 deletions

View File

@ -1,4 +1,4 @@
From 4f23ede23ade4b6f09398c7b12f6044ad88914d7 Mon Sep 17 00:00:00 2001 From f8d45609bd1247f999df8ac62ca914e8b18e0b28 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co> From: Aikar <aikar@aikar.co>
Date: Fri, 28 Sep 2018 20:46:29 -0400 Date: Fri, 28 Sep 2018 20:46:29 -0400
Subject: [PATCH] Optimize Light Recalculations Subject: [PATCH] Optimize Light Recalculations
@ -10,10 +10,22 @@ do not impact light calculations.
So the only way light should change, is if the block itself So the only way light should change, is if the block itself
changes from 1 block to another. changes from 1 block to another.
Also optimizes to not repeatedly look up the same chunk for
light lookups.
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 53aab97866..e4bda70bb9 100644 index 9162151e2a..651bb23be9 100644
--- a/src/main/java/net/minecraft/server/Chunk.java --- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -347,7 +347,7 @@ public class Chunk implements IChunkAccess {
private void a(int i, int j, int k, int l) {
if (l > k && this.areNeighborsLoaded(1)) { // Paper
for (int i1 = k; i1 < l; ++i1) {
- this.world.c(EnumSkyBlock.SKY, new BlockPosition(i, i1, j));
+ this.world.updateBrightness(EnumSkyBlock.SKY, new BlockPosition(i, i1, j), this); // Paper
}
this.x = true;
@@ -578,7 +578,7 @@ public class Chunk implements IChunkAccess { @@ -578,7 +578,7 @@ public class Chunk implements IChunkAccess {
} else { } else {
if (flag1) { if (flag1) {
@ -24,7 +36,7 @@ index 53aab97866..e4bda70bb9 100644
int i1 = iblockdata.b(this.world, blockposition); int i1 = iblockdata.b(this.world, blockposition);
int j1 = iblockdata1.b(this.world, blockposition); int j1 = iblockdata1.b(this.world, blockposition);
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 13f69f1b82..763401835d 100644 index 13f69f1b82..4179ba7cd8 100644
--- a/src/main/java/net/minecraft/server/World.java --- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java
@@ -444,7 +444,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc @@ -444,7 +444,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
@ -36,6 +48,30 @@ index 13f69f1b82..763401835d 100644
this.methodProfiler.a("checkLight"); this.methodProfiler.a("checkLight");
chunk.runOrQueueLightUpdate(() -> this.r(blockposition)); // Paper - Queue light update chunk.runOrQueueLightUpdate(() -> this.r(blockposition)); // Paper - Queue light update
this.methodProfiler.e(); this.methodProfiler.e();
@@ -588,8 +588,9 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
}
if (this.worldProvider.g()) {
- for (i1 = k; i1 <= l; ++i1) {
- this.c(EnumSkyBlock.SKY, new BlockPosition(i, i1, j));
+ Chunk chunk = getChunkIfLoaded(i >> 4, j >> 4); // Paper
+ for (i1 = k; chunk != null && i1 <= l; ++i1) { // Paper
+ this.updateBrightness(EnumSkyBlock.SKY, new BlockPosition(i, i1, j), chunk); // Paper
}
}
@@ -2293,6 +2294,11 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
public boolean c(EnumSkyBlock enumskyblock, BlockPosition blockposition) {
// CraftBukkit start - Use neighbor cache instead of looking up
Chunk chunk = this.getChunkIfLoaded(blockposition.getX() >> 4, blockposition.getZ() >> 4);
+ // Paper start - optimize light updates where chunk is known
+ return updateBrightness(enumskyblock, blockposition, chunk);
+ }
+ public boolean updateBrightness(EnumSkyBlock enumskyblock, BlockPosition blockposition, Chunk chunk) {
+ // Paper end
if (chunk == null || !chunk.areNeighborsLoaded(1) /*!this.areChunksLoaded(blockposition, 17, false)*/) {
// CraftBukkit end
return false;
-- --
2.19.0 2.19.0

View File

@ -1,4 +1,4 @@
From e37fa915dcd5af6254627ba1f05d5afe9692ee9b Mon Sep 17 00:00:00 2001 From 17559df2144117d9f2ad7bf70d54fbd8d8c0a8db Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co> From: Aikar <aikar@aikar.co>
Date: Fri, 28 Sep 2018 21:49:53 -0400 Date: Fri, 28 Sep 2018 21:49:53 -0400
Subject: [PATCH] Fix issues with entity loss due to unloaded chunks Subject: [PATCH] Fix issues with entity loss due to unloaded chunks
@ -18,10 +18,10 @@ This change ensures the chunks are always loaded when entities are
added to the world, or a valid entity moves between chunks. added to the world, or a valid entity moves between chunks.
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 763401835d..3379b68acb 100644 index 4179ba7cd8..d659ffe9ba 100644
--- a/src/main/java/net/minecraft/server/World.java --- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java
@@ -1145,7 +1145,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc @@ -1146,7 +1146,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
int i = MathHelper.floor(entity.locX / 16.0D); int i = MathHelper.floor(entity.locX / 16.0D);
int j = MathHelper.floor(entity.locZ / 16.0D); int j = MathHelper.floor(entity.locZ / 16.0D);
@ -30,7 +30,7 @@ index 763401835d..3379b68acb 100644
// Paper start - Set origin location when the entity is being added to the world // Paper start - Set origin location when the entity is being added to the world
if (entity.origin == null) { if (entity.origin == null) {
@@ -1649,7 +1649,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc @@ -1650,7 +1650,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
this.getChunkAt(entity.ae, entity.ag).a(entity, entity.af); this.getChunkAt(entity.ae, entity.ag).a(entity, entity.af);
} }