aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0088-Optimize-Chunk-Access.patch
diff options
context:
space:
mode:
Diffstat (limited to 'Spigot-Server-Patches/0088-Optimize-Chunk-Access.patch')
-rw-r--r--Spigot-Server-Patches/0088-Optimize-Chunk-Access.patch46
1 files changed, 46 insertions, 0 deletions
diff --git a/Spigot-Server-Patches/0088-Optimize-Chunk-Access.patch b/Spigot-Server-Patches/0088-Optimize-Chunk-Access.patch
new file mode 100644
index 0000000000..86cd49fb74
--- /dev/null
+++ b/Spigot-Server-Patches/0088-Optimize-Chunk-Access.patch
@@ -0,0 +1,46 @@
+From 15890a007fe5797522d8b42f028835b2b2ff6d05 Mon Sep 17 00:00:00 2001
+From: Aikar <[email protected]>
+Date: Thu, 27 Aug 2015 01:15:02 -0400
+Subject: [PATCH] Optimize Chunk Access
+
+getting a loaded chunk is one of the most hottest pieces of code in the game.
+getChunkAt is called for the same chunk multiple times in a row, often from getType();
+
+Optimize this look up by using a Last Access cache.
+
+diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
+index b0a82e7ed..a7e8a3f7d 100644
+--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
++++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
+@@ -27,7 +27,27 @@ public class ChunkProviderServer implements IChunkProvider {
+ public final Set<Long> unloadQueue = Sets.newHashSet();
+ public final ChunkGenerator chunkGenerator;
+ private final IChunkLoader chunkLoader;
+- public final Long2ObjectMap<Chunk> chunks = new Long2ObjectOpenHashMap(8192);
++ // Paper start
++ protected Chunk lastChunkByPos = null;
++ public Long2ObjectOpenHashMap<Chunk> chunks = new Long2ObjectOpenHashMap<Chunk>(8192) {
++
++ @Override
++ public Chunk get(long key) {
++ if (lastChunkByPos != null && key == lastChunkByPos.chunkKey) {
++ return lastChunkByPos;
++ }
++ return lastChunkByPos = super.get(key);
++ }
++
++ @Override
++ public Chunk remove(long key) {
++ if (lastChunkByPos != null && key == lastChunkByPos.chunkKey) {
++ lastChunkByPos = null;
++ }
++ return super.remove(key);
++ }
++ }; // CraftBukkit
++ // Paper end
+ public final WorldServer world;
+
+ public ChunkProviderServer(WorldServer worldserver, IChunkLoader ichunkloader, ChunkGenerator chunkgenerator) {
+--
+2.12.2
+