mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-03 23:07:40 +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
6ca5deba8b
commit
f36773fd9c
@ -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
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
@@ -0,0 +0,0 @@ public class ChunkProviderServer implements IChunkProvider {
|
||||
@ -112,4 +112,12 @@ index d16fc452e3..2d10f4aa37 100644
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
}
|
||||
}
|
||||
--
|
Loading…
Reference in New Issue
Block a user