2017-06-09 20:29:44 +08:00
|
|
|
From 0a27cc32e4ce4ca5067a78cb8d56777f9b71deae Mon Sep 17 00:00:00 2001
|
2016-06-19 11:33:57 +08:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sat, 18 Jun 2016 23:22:12 -0400
|
|
|
|
Subject: [PATCH] Delay Chunk Unloads based on Player Movement
|
|
|
|
|
|
|
|
When players are moving in the world, doing things such as building or exploring,
|
|
|
|
they will commonly go back and forth in a small area. This causes a ton of chunk load
|
|
|
|
and unload activity on the edge chunks of their view distance.
|
|
|
|
|
|
|
|
A simple back and forth movement in 6 blocks could spam a chunk to thrash a
|
|
|
|
loading and unload cycle over and over again.
|
|
|
|
|
|
|
|
This is very wasteful. This system introduces a delay of inactivity on a chunk
|
|
|
|
before it actually unloads, which is maintained separately from ChunkGC.
|
|
|
|
|
|
|
|
This allows servers with smaller worlds who do less long distance exploring to stop
|
|
|
|
wasting cpu cycles on saving/unloading/reloading chunks repeatedly.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2017-05-15 02:05:01 +08:00
|
|
|
index d5d6e7fcd..ef60c15bd 100644
|
2016-06-19 11:33:57 +08:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2017-05-15 02:05:01 +08:00
|
|
|
@@ -346,4 +346,13 @@ public class PaperWorldConfig {
|
2016-07-29 09:54:48 +08:00
|
|
|
private void isHopperPushBased() {
|
2016-07-29 09:57:36 +08:00
|
|
|
isHopperPushBased = getBoolean("hopper.push-based", false);
|
2016-06-19 11:33:57 +08:00
|
|
|
}
|
2016-07-29 09:54:48 +08:00
|
|
|
+
|
2016-06-19 11:33:57 +08:00
|
|
|
+ public long delayChunkUnloadsBy;
|
|
|
|
+ private void delayChunkUnloadsBy() {
|
2016-07-29 09:57:36 +08:00
|
|
|
+ delayChunkUnloadsBy = PaperConfig.getSeconds(getString("delay-chunk-unloads-by", "10s"));
|
2016-06-19 11:33:57 +08:00
|
|
|
+ if (delayChunkUnloadsBy > 0) {
|
|
|
|
+ log("Delaying chunk unloads by " + delayChunkUnloadsBy + " seconds");
|
|
|
|
+ delayChunkUnloadsBy *= 1000;
|
|
|
|
+ }
|
|
|
|
+ }
|
2016-07-29 09:54:48 +08:00
|
|
|
}
|
2016-06-19 11:33:57 +08:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
2017-06-09 20:29:44 +08:00
|
|
|
index 0845d1ffe..a0b5cd56b 100644
|
2016-06-19 11:33:57 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2016-06-23 10:18:41 +08:00
|
|
|
@@ -30,6 +30,7 @@ public class Chunk {
|
|
|
|
private boolean j;
|
2016-06-19 11:33:57 +08:00
|
|
|
public final World world;
|
|
|
|
public final int[] heightMap;
|
|
|
|
+ public Long scheduledForUnload; // Paper - delay chunk unloads
|
|
|
|
public final int locX;
|
|
|
|
public final int locZ;
|
|
|
|
private boolean m;
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2017-05-15 02:05:01 +08:00
|
|
|
index a512a4113..9836c0c5a 100644
|
2016-06-19 11:33:57 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2017-02-04 17:59:44 +08:00
|
|
|
@@ -315,6 +315,19 @@ public class ChunkProviderServer implements IChunkProvider {
|
2017-01-31 12:33:54 +08:00
|
|
|
|
|
|
|
activityAccountant.endActivity(); // Spigot
|
2016-06-19 11:33:57 +08:00
|
|
|
}
|
|
|
|
+ // Paper start - delayed chunk unloads
|
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
|
+ long unloadAfter = world.paperConfig.delayChunkUnloadsBy;
|
|
|
|
+ if (unloadAfter > 0) {
|
|
|
|
+ //noinspection Convert2streamapi
|
|
|
|
+ for (Chunk chunk : chunks.values()) {
|
|
|
|
+ if (chunk.scheduledForUnload != null && now - chunk.scheduledForUnload > unloadAfter) {
|
|
|
|
+ chunk.scheduledForUnload = null;
|
|
|
|
+ unload(chunk);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
2017-05-15 02:05:01 +08:00
|
|
|
this.chunkLoader.b();
|
2016-06-19 11:33:57 +08:00
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java
|
2017-05-15 02:05:01 +08:00
|
|
|
index 3d30e1831..48a008e0a 100644
|
2016-06-19 11:33:57 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerChunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerChunk.java
|
|
|
|
@@ -32,8 +32,16 @@ public class PlayerChunk {
|
|
|
|
public void run() {
|
|
|
|
loadInProgress = false;
|
|
|
|
PlayerChunk.this.chunk = PlayerChunk.this.playerChunkMap.getWorld().getChunkProviderServer().getOrLoadChunkAt(location.x, location.z);
|
|
|
|
+ markChunkUsed(); // Paper - delay chunk unloads
|
|
|
|
}
|
|
|
|
};
|
|
|
|
+ // Paper start - delay chunk unloads
|
|
|
|
+ public final void markChunkUsed() {
|
|
|
|
+ if (chunk != null && chunk.scheduledForUnload != null) {
|
|
|
|
+ chunk.scheduledForUnload = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
public PlayerChunk(PlayerChunkMap playerchunkmap, int i, int j) {
|
|
|
|
@@ -42,6 +50,7 @@ public class PlayerChunk {
|
|
|
|
// CraftBukkit start
|
|
|
|
loadInProgress = true;
|
|
|
|
this.chunk = playerchunkmap.getWorld().getChunkProviderServer().getChunkAt(i, j, loadedRunnable, false);
|
|
|
|
+ markChunkUsed(); // Paper - delay chunk unloads
|
|
|
|
// CraftBukkit end
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -110,6 +119,7 @@ public class PlayerChunk {
|
|
|
|
if (!loadInProgress) {
|
|
|
|
loadInProgress = true;
|
|
|
|
this.chunk = playerChunkMap.getWorld().getChunkProviderServer().getChunkAt(this.location.x, this.location.z, loadedRunnable, flag);
|
|
|
|
+ markChunkUsed(); // Paper - delay chunk unloads
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
2017-05-05 07:08:52 +08:00
|
|
|
index 0a0b5261b..14ea89c91 100644
|
2016-06-19 11:33:57 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
2017-01-31 12:33:54 +08:00
|
|
|
@@ -487,7 +487,13 @@ public class PlayerChunkMap {
|
2016-06-19 11:33:57 +08:00
|
|
|
Chunk chunk = playerchunk.f();
|
|
|
|
|
|
|
|
if (chunk != null) {
|
|
|
|
- this.getWorld().getChunkProviderServer().unload(chunk);
|
|
|
|
+ // Paper start - delay chunk unloads
|
|
|
|
+ if (world.paperConfig.delayChunkUnloadsBy <= 0) {
|
|
|
|
+ this.getWorld().getChunkProviderServer().unload(chunk);
|
|
|
|
+ } else {
|
|
|
|
+ chunk.scheduledForUnload = System.currentTimeMillis();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2017-06-09 20:29:44 +08:00
|
|
|
index 24b4a7ea7..416e86af3 100644
|
2016-06-19 11:33:57 +08:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2017-06-09 20:29:44 +08:00
|
|
|
@@ -1568,7 +1568,7 @@ public class CraftWorld implements World {
|
2016-06-19 11:33:57 +08:00
|
|
|
ChunkProviderServer cps = world.getChunkProviderServer();
|
|
|
|
for (net.minecraft.server.Chunk chunk : cps.chunks.values()) {
|
|
|
|
// If in use, skip it
|
|
|
|
- if (isChunkInUse(chunk.locX, chunk.locZ)) {
|
|
|
|
+ if (isChunkInUse(chunk.locX, chunk.locZ) || chunk.scheduledForUnload != null) { // Paper - delayed chunk unloads
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
--
|
2017-05-15 02:05:01 +08:00
|
|
|
2.13.0
|
2016-06-19 11:33:57 +08:00
|
|
|
|