mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 07:48:53 +01:00
Use Last Access Cache for isLoaded calls
this should provide a pretty good across-the-board performance improvement for the entire server, as it's very common for code to check if (isLoaded(x, z)) { then do something on that chunk } Previously, containsKey would not read or set the last access cache By making it do get() != null, we gain the benefits of last access and also improves thread safey for async isLoaded checks This exact usage scenario is used in Entity movement, so that alone saves us up to 5%~ of CPU time for Entity movement.
This commit is contained in:
parent
e9305f96a3
commit
d07f7197f2
1 changed files with 11 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
|||
From eb8942dae2dd6dbc8a32b05c0a502a4a507d7233 Mon Sep 17 00:00:00 2001
|
||||
From 7ac07ac07ac07ac07ac07ac07ac07ac07ac07ac0 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
|
||||
|
@ -9,7 +9,7 @@ getChunkAt is called for the same chunk multiple times in a row, often from getT
|
|||
Optimize this look up by using a Last Access cache.
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/ChunkMap.java b/src/main/java/net/minecraft/server/ChunkMap.java
|
||||
index 4b8b77710b..71ddaf591e 100644
|
||||
index 7ac07ac07ac0..7ac07ac07ac0 100644
|
||||
--- a/src/main/java/net/minecraft/server/ChunkMap.java
|
||||
+++ b/src/main/java/net/minecraft/server/ChunkMap.java
|
||||
@@ -15,6 +15,7 @@ public class ChunkMap extends Long2ObjectOpenHashMap<Chunk> {
|
||||
|
@ -71,7 +71,7 @@ index 4b8b77710b..71ddaf591e 100644
|
|||
public Chunk a(Object object) {
|
||||
return this.a(((Long) object).longValue());
|
||||
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
||||
index d16fc452e3..2d10f4aa37 100644
|
||||
index 7ac07ac07ac0..7ac07ac07ac0 100644
|
||||
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
||||
@@ -78,15 +78,16 @@ public class ChunkProviderServer implements IChunkProvider {
|
||||
|
@ -112,6 +112,14 @@ index d16fc452e3..2d10f4aa37 100644
|
|||
}
|
||||
return true;
|
||||
}
|
||||
@@ -379,6 +380,6 @@ public class ChunkProviderServer implements IChunkProvider {
|
||||
}
|
||||
|
||||
public boolean isLoaded(int i, int j) {
|
||||
- return this.chunks.containsKey(ChunkCoordIntPair.a(i, j));
|
||||
+ return this.chunks.get(ChunkCoordIntPair.asLong(i, j)) != null; // Paper - use get for last access
|
||||
}
|
||||
}
|
||||
--
|
||||
2.19.1
|
||||
|
||||
|
|
Loading…
Reference in a new issue