2016-04-01 06:35:44 +02:00
|
|
|
From 2abc0d00312f85e3dcef3520fc9cb106ae4bad3b Mon Sep 17 00:00:00 2001
|
2016-03-22 06:46:32 +01: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 04:44:35 +01:00
|
|
|
getChunkAt is called for the same chunk multiple times in a row, often from getType();
|
2016-03-22 06:46:32 +01: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-03-29 03:01:42 +02:00
|
|
|
index ac35cf4..6e3d17b 100644
|
2016-03-22 06:46:32 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2016-03-25 07:38:38 +01:00
|
|
|
@@ -30,6 +30,7 @@ public class Chunk {
|
2016-03-22 06:46:32 +01:00
|
|
|
private boolean i;
|
|
|
|
public final World world;
|
|
|
|
public final int[] heightMap;
|
|
|
|
+ public final long chunkKey; // Paper
|
|
|
|
public final int locX;
|
|
|
|
public final int locZ;
|
|
|
|
private boolean l;
|
2016-03-25 07:38:38 +01:00
|
|
|
@@ -97,6 +98,7 @@ public class Chunk {
|
2016-03-22 06:46:32 +01: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-04-01 06:35:44 +02:00
|
|
|
index f5a2580..5ec5bf6 100644
|
2016-03-22 06:46:32 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2016-04-01 06:35:44 +02:00
|
|
|
@@ -24,7 +24,26 @@ public class ChunkProviderServer implements IChunkProvider {
|
2016-03-22 06:46:32 +01:00
|
|
|
public final ChunkUnloadQueue unloadQueue = new ChunkUnloadQueue(); // CraftBukkit - LongHashSet // Paper -> ChunkUnloadQueue
|
|
|
|
public final ChunkGenerator chunkGenerator; // CraftBukkit - public
|
|
|
|
private final IChunkLoader chunkLoader;
|
|
|
|
- public LongObjectHashMap<Chunk> chunks = new LongObjectHashMap<Chunk>(); // CraftBukkit
|
|
|
|
+ // Paper start
|
|
|
|
+ protected Chunk lastChunkByPos = null;
|
|
|
|
+ public LongObjectHashMap<Chunk> chunks = new LongObjectHashMap<Chunk>() {
|
|
|
|
+ @Override
|
|
|
|
+ public Chunk get(long key) {
|
|
|
|
+ if (lastChunkByPos != null && key == lastChunkByPos.chunkKey) {
|
|
|
|
+ return lastChunkByPos;
|
|
|
|
+ }
|
2016-03-23 04:44:35 +01:00
|
|
|
+ return lastChunkByPos = super.get(key);
|
2016-03-22 06:46:32 +01:00
|
|
|
+ }
|
2016-04-01 06:35:44 +02:00
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Chunk remove(long key) {
|
|
|
|
+ if (lastChunkByPos != null && key == lastChunkByPos.chunkKey) {
|
|
|
|
+ lastChunkByPos = null;
|
|
|
|
+ }
|
|
|
|
+ return super.remove(key);
|
|
|
|
+ }
|
2016-03-22 06:46:32 +01:00
|
|
|
+ }; // CraftBukkit
|
|
|
|
+ // Paper end
|
|
|
|
// private final LongHashMap<Chunk> chunks = new LongHashMap();
|
|
|
|
// private final List<Chunk> chunkList = Lists.newArrayList();
|
|
|
|
public final WorldServer world;
|
|
|
|
--
|
2016-03-31 02:50:23 +02:00
|
|
|
2.8.0
|
2016-03-22 06:46:32 +01:00
|
|
|
|