3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/Spigot-Server-Patches/0097-Optimize-Chunk-Access.patch

47 Zeilen
1.8 KiB
Diff

2016-06-23 04:18:41 +02:00
From e5e40424dbd26cdf7935353671f5322e25464303 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/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2016-06-23 04:18:41 +02:00
index d814670..36515cd 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2016-06-23 04:18:41 +02:00
@@ -26,7 +26,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;
private final IChunkLoader chunkLoader;
2016-05-12 04:07:46 +02:00
- public final Long2ObjectMap<Chunk> chunks = new Long2ObjectOpenHashMap(8192);
+ // Paper start
+ protected Chunk lastChunkByPos = null;
2016-05-12 04:07:46 +02:00
+ 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;
2016-05-12 04:07:46 +02:00
public ChunkProviderServer(WorldServer worldserver, IChunkLoader ichunkloader, ChunkGenerator chunkgenerator) {
--
2016-06-23 04:18:41 +02:00
2.9.0