2016-05-12 02:07:46 +00:00
|
|
|
From 1917871be3d7d048b496022ef54eaf230ff2a900 Mon Sep 17 00:00:00 2001
|
2016-03-22 05:46:32 +00:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
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.
|
2016-03-23 03:44:35 +00:00
|
|
|
getChunkAt is called for the same chunk multiple times in a row, often from getType();
|
2016-03-22 05:46:32 +00:00
|
|
|
|
|
|
|
Optimize this look up by using a Last Access cache.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
2016-05-12 02:07:46 +00:00
|
|
|
index eb60455..22e4728 100644
|
2016-03-22 05:46:32 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2016-03-25 06:38:38 +00:00
|
|
|
@@ -30,6 +30,7 @@ public class Chunk {
|
2016-05-12 02:07:46 +00:00
|
|
|
private boolean j;
|
2016-03-22 05:46:32 +00:00
|
|
|
public final World world;
|
|
|
|
public final int[] heightMap;
|
|
|
|
+ public final long chunkKey; // Paper
|
|
|
|
public final int locX;
|
|
|
|
public final int locZ;
|
2016-05-12 02:07:46 +00:00
|
|
|
private boolean m;
|
|
|
|
@@ -96,6 +97,7 @@ public class Chunk {
|
2016-03-22 05:46:32 +00:00
|
|
|
this.world = world;
|
|
|
|
this.locX = i;
|
|
|
|
this.locZ = j;
|
|
|
|
+ this.chunkKey = org.bukkit.craftbukkit.util.LongHash.toLong(this.locX, this.locZ); // Paper
|
|
|
|
this.heightMap = new int[256];
|
|
|
|
|
|
|
|
for (int k = 0; k < this.entitySlices.length; ++k) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2016-05-12 02:07:46 +00:00
|
|
|
index 32b71c6..3d36d7a 100644
|
2016-03-22 05:46:32 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2016-05-12 02:07:46 +00:00
|
|
|
@@ -27,7 +27,27 @@ public class ChunkProviderServer implements IChunkProvider {
|
|
|
|
public final Set<Long> unloadQueue = Sets.newHashSet(); // PAIL: private -> public
|
|
|
|
public final ChunkGenerator chunkGenerator;
|
2016-03-22 05:46:32 +00:00
|
|
|
private final IChunkLoader chunkLoader;
|
2016-05-12 02:07:46 +00:00
|
|
|
- public final Long2ObjectMap<Chunk> chunks = new Long2ObjectOpenHashMap(8192);
|
2016-03-22 05:46:32 +00:00
|
|
|
+ // Paper start
|
|
|
|
+ protected Chunk lastChunkByPos = null;
|
2016-05-12 02:07:46 +00:00
|
|
|
+ public Long2ObjectOpenHashMap<Chunk> chunks = new Long2ObjectOpenHashMap<Chunk>(8192) {
|
|
|
|
+
|
2016-03-22 05:46:32 +00:00
|
|
|
+ @Override
|
|
|
|
+ public Chunk get(long key) {
|
|
|
|
+ if (lastChunkByPos != null && key == lastChunkByPos.chunkKey) {
|
|
|
|
+ return lastChunkByPos;
|
|
|
|
+ }
|
2016-03-23 03:44:35 +00:00
|
|
|
+ return lastChunkByPos = super.get(key);
|
2016-03-22 05:46:32 +00:00
|
|
|
+ }
|
2016-04-01 04:35:44 +00:00
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Chunk remove(long key) {
|
|
|
|
+ if (lastChunkByPos != null && key == lastChunkByPos.chunkKey) {
|
|
|
|
+ lastChunkByPos = null;
|
|
|
|
+ }
|
|
|
|
+ return super.remove(key);
|
|
|
|
+ }
|
2016-03-22 05:46:32 +00:00
|
|
|
+ }; // CraftBukkit
|
|
|
|
+ // Paper end
|
|
|
|
public final WorldServer world;
|
2016-05-12 02:07:46 +00:00
|
|
|
|
|
|
|
public ChunkProviderServer(WorldServer worldserver, IChunkLoader ichunkloader, ChunkGenerator chunkgenerator) {
|
2016-03-22 05:46:32 +00:00
|
|
|
--
|
2016-05-12 02:07:46 +00:00
|
|
|
2.8.2
|
2016-03-22 05:46:32 +00:00
|
|
|
|