Paper/Spigot-Server-Patches/0096-Optimize-Chunk-Access.patch
Aikar 3faaaab75d Optimize isInvalidYLocation, getType and getBlockData
Some pretty micro optimizations, but this is the hottest method in the server....

This will drastically reduce number of operations to perform getType

the 2 previous patches was squashed into 1
2016-06-22 22:43:02 -04:00

47 lines
1.8 KiB
Diff

From 11f18326b98f9ebe0906aee6bad03a02e9ab6f95 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
index d814670..36515cd 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -26,7 +26,27 @@ public class ChunkProviderServer implements IChunkProvider {
public final Set<Long> unloadQueue = Sets.newHashSet();
public final ChunkGenerator chunkGenerator;
private final IChunkLoader chunkLoader;
- public final Long2ObjectMap<Chunk> chunks = new Long2ObjectOpenHashMap(8192);
+ // Paper start
+ protected Chunk lastChunkByPos = null;
+ 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;
public ChunkProviderServer(WorldServer worldserver, IChunkLoader ichunkloader, ChunkGenerator chunkgenerator) {
--
2.9.0