2018-07-04 09:55:24 +02:00
|
|
|
From 4f5d96217a3ec5d72b3f19f874b53fd13d506b97 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/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2018-04-08 02:44:14 +02:00
|
|
|
index 4e7e8e5fd..1771a1794 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-11-17 03:23:38 +01:00
|
|
|
@@ -27,7 +27,27 @@ public class ChunkProviderServer implements IChunkProvider {
|
2016-06-09 05:57:14 +02:00
|
|
|
public final Set<Long> unloadQueue = Sets.newHashSet();
|
2016-05-12 04:07:46 +02:00
|
|
|
public final ChunkGenerator chunkGenerator;
|
2016-03-22 06:46:32 +01:00
|
|
|
private final IChunkLoader chunkLoader;
|
2016-05-12 04:07:46 +02:00
|
|
|
- public final Long2ObjectMap<Chunk> chunks = new Long2ObjectOpenHashMap(8192);
|
2016-03-22 06:46:32 +01:00
|
|
|
+ // Paper start
|
|
|
|
+ protected Chunk lastChunkByPos = null;
|
2016-05-12 04:07:46 +02:00
|
|
|
+ public Long2ObjectOpenHashMap<Chunk> chunks = new Long2ObjectOpenHashMap<Chunk>(8192) {
|
|
|
|
+
|
2016-03-22 06:46:32 +01:00
|
|
|
+ @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
|
|
|
|
public final WorldServer world;
|
2016-05-12 04:07:46 +02:00
|
|
|
|
|
|
|
public ChunkProviderServer(WorldServer worldserver, IChunkLoader ichunkloader, ChunkGenerator chunkgenerator) {
|
2016-03-22 06:46:32 +01:00
|
|
|
--
|
2018-07-04 09:55:24 +02:00
|
|
|
2.18.0
|
2016-03-22 06:46:32 +01:00
|
|
|
|