mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
63 lines
No EOL
2.8 KiB
Diff
63 lines
No EOL
2.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
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.
|
|
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/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
|
@@ -0,0 +0,0 @@ public class Chunk {
|
|
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;
|
|
@@ -0,0 +0,0 @@ public class Chunk {
|
|
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
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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 {
|
|
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;
|
|
+ }
|
|
+ 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
|
|
// private final LongHashMap<Chunk> chunks = new LongHashMap();
|
|
// private final List<Chunk> chunkList = Lists.newArrayList();
|
|
public final WorldServer world;
|
|
--
|