From f36773fd9c2398b3d418eb0f41ef1202d8e58d25 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. --- Spigot-Server-Patches/Optimize-Chunk-Access.patch | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Spigot-Server-Patches/Optimize-Chunk-Access.patch b/Spigot-Server-Patches/Optimize-Chunk-Access.patch index 2049f6db48..dcbc532c8a 100644 --- a/Spigot-Server-Patches/Optimize-Chunk-Access.patch +++ b/Spigot-Server-Patches/Optimize-Chunk-Access.patch @@ -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 @@ -0,0 +0,0 @@ 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 @@ -0,0 +0,0 @@ public class ChunkProviderServer implements IChunkProvider { @@ -112,4 +112,12 @@ index d16fc452e3..2d10f4aa37 100644 } return true; } +@@ -0,0 +0,0 @@ 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 + } + } -- \ No newline at end of file