From d07f7197f2cc1cd88356ae16a750920bf82411b8 Mon Sep 17 00:00:00 2001 From: Aikar Date: Tue, 23 Oct 2018 23:50:51 -0400 Subject: [PATCH] Use Last Access Cache for isLoaded calls this should provide a pretty good across-the-board performance improvement for the entire server, as it's very common for code to check if (isLoaded(x, z)) { then do something on that chunk } Previously, containsKey would not read or set the last access cache By making it do get() != null, we gain the benefits of last access and also improves thread safey for async isLoaded checks This exact usage scenario is used in Entity movement, so that alone saves us up to 5%~ of CPU time for Entity movement. --- .../0078-Optimize-Chunk-Access.patch | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Spigot-Server-Patches/0078-Optimize-Chunk-Access.patch b/Spigot-Server-Patches/0078-Optimize-Chunk-Access.patch index 4bfae5f308..42f40e6c31 100644 --- a/Spigot-Server-Patches/0078-Optimize-Chunk-Access.patch +++ b/Spigot-Server-Patches/0078-Optimize-Chunk-Access.patch @@ -1,4 +1,4 @@ -From eb8942dae2dd6dbc8a32b05c0a502a4a507d7233 Mon Sep 17 00:00:00 2001 +From 7ac07ac07ac07ac07ac07ac07ac07ac07ac07ac0 Mon Sep 17 00:00:00 2001 From: Aikar Date: Thu, 27 Aug 2015 01:15:02 -0400 Subject: [PATCH] Optimize Chunk Access @@ -9,7 +9,7 @@ getChunkAt is called for the same chunk multiple times in a row, often from getT Optimize this look up by using a Last Access cache. diff --git a/src/main/java/net/minecraft/server/ChunkMap.java b/src/main/java/net/minecraft/server/ChunkMap.java -index 4b8b77710b..71ddaf591e 100644 +index 7ac07ac07ac0..7ac07ac07ac0 100644 --- a/src/main/java/net/minecraft/server/ChunkMap.java +++ b/src/main/java/net/minecraft/server/ChunkMap.java @@ -15,6 +15,7 @@ public class ChunkMap extends Long2ObjectOpenHashMap { @@ -71,7 +71,7 @@ index 4b8b77710b..71ddaf591e 100644 public Chunk a(Object object) { return this.a(((Long) object).longValue()); diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java -index d16fc452e3..2d10f4aa37 100644 +index 7ac07ac07ac0..7ac07ac07ac0 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -78,15 +78,16 @@ public class ChunkProviderServer implements IChunkProvider { @@ -112,6 +112,14 @@ index d16fc452e3..2d10f4aa37 100644 } return true; } +@@ -379,6 +380,6 @@ public class ChunkProviderServer implements IChunkProvider { + } + + public boolean isLoaded(int i, int j) { +- return this.chunks.containsKey(ChunkCoordIntPair.a(i, j)); ++ return this.chunks.get(ChunkCoordIntPair.asLong(i, j)) != null; // Paper - use get for last access + } + } -- 2.19.1