Paper/patches/unapplied/server/0099-Faster-redstone-torch-rapid-clock-removal.patch

82 Zeilen
4.4 KiB
Diff

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martin Panzer <postremus1996@googlemail.com>
Date: Mon, 23 May 2016 12:12:37 +0200
Subject: [PATCH] Faster redstone torch rapid clock removal
Only resize the the redstone torch list once, since resizing arrays / lists is costly
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
Rewrite chunk system (#8177) Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 10:02:51 +02:00
index 39b2071a6fc6510929416ccbdf2022cf471ab26c..807df663f710311276d69288875bb80e7fa37893 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -167,6 +167,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-11 14:02:28 +02:00
private org.spigotmc.TickLimiter tileLimiter;
private int tileTickPosition;
public final Map<Explosion.CacheKey, Float> explosionDensityCache = new HashMap<>(); // Paper - Optimize explosions
2021-06-12 07:20:08 +02:00
+ public java.util.ArrayDeque<net.minecraft.world.level.block.RedstoneTorchBlock.Toggle> redstoneUpdateInfos; // Paper - Move from Map in BlockRedstoneTorch to here
2021-06-11 14:02:28 +02:00
public CraftWorld getWorld() {
return this.world;
diff --git a/src/main/java/net/minecraft/world/level/block/RedstoneTorchBlock.java b/src/main/java/net/minecraft/world/level/block/RedstoneTorchBlock.java
2022-06-07 21:55:39 +02:00
index 9b6f8508d16bcecd9dc148f75598655e3585f175..da07fce0cf7c9fbdb57d2c59e431b59bf583bf50 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/RedstoneTorchBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/RedstoneTorchBlock.java
@@ -21,7 +21,7 @@ import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
public class RedstoneTorchBlock extends TorchBlock {
public static final BooleanProperty LIT = BlockStateProperties.LIT;
- private static final Map<BlockGetter, List<RedstoneTorchBlock.Toggle>> RECENT_TOGGLES = new WeakHashMap();
+ // Paper - Move the mapped list to World
2021-06-12 07:20:08 +02:00
public static final int RECENT_TOGGLE_TIMER = 60;
public static final int MAX_RECENT_TOGGLES = 8;
public static final int RESTART_DELAY = 160;
@@ -72,11 +72,15 @@ public class RedstoneTorchBlock extends TorchBlock {
2021-06-11 14:02:28 +02:00
@Override
2022-06-07 21:55:39 +02:00
public void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) {
2021-11-23 14:22:49 +01:00
boolean flag = this.hasNeighborSignal(world, pos, state);
2021-06-11 14:02:28 +02:00
- List list = (List) RedstoneTorchBlock.RECENT_TOGGLES.get(world);
-
- while (list != null && !list.isEmpty() && world.getGameTime() - ((RedstoneTorchBlock.Toggle) list.get(0)).when > 60L) {
- list.remove(0);
+ // Paper start
+ java.util.ArrayDeque<RedstoneTorchBlock.Toggle> redstoneUpdateInfos = world.redstoneUpdateInfos;
+ if (redstoneUpdateInfos != null) {
+ RedstoneTorchBlock.Toggle curr;
2021-06-12 07:20:08 +02:00
+ while ((curr = redstoneUpdateInfos.peek()) != null && world.getGameTime() - curr.when > 60L) {
2021-06-11 14:02:28 +02:00
+ redstoneUpdateInfos.poll();
+ }
}
+ // Paper end
// CraftBukkit start
org.bukkit.plugin.PluginManager manager = world.getCraftServer().getPluginManager();
2021-06-12 07:20:08 +02:00
@@ -152,9 +156,12 @@ public class RedstoneTorchBlock extends TorchBlock {
2021-06-11 14:02:28 +02:00
}
private static boolean isToggledTooFrequently(Level world, BlockPos pos, boolean addNew) {
- List<RedstoneTorchBlock.Toggle> list = (List) RedstoneTorchBlock.RECENT_TOGGLES.computeIfAbsent(world, (iblockaccess) -> {
- return Lists.newArrayList();
- });
+ // Paper start
+ java.util.ArrayDeque<RedstoneTorchBlock.Toggle> list = world.redstoneUpdateInfos;
+ if (list == null) {
+ list = world.redstoneUpdateInfos = new java.util.ArrayDeque<>();
+ }
+
if (addNew) {
list.add(new RedstoneTorchBlock.Toggle(pos.immutable(), world.getGameTime()));
2021-06-12 07:20:08 +02:00
@@ -162,9 +169,9 @@ public class RedstoneTorchBlock extends TorchBlock {
2021-06-11 14:02:28 +02:00
int i = 0;
- for (int j = 0; j < list.size(); ++j) {
- RedstoneTorchBlock.Toggle blockredstonetorch_redstoneupdateinfo = (RedstoneTorchBlock.Toggle) list.get(j);
-
+ for (java.util.Iterator<RedstoneTorchBlock.Toggle> iterator = list.iterator(); iterator.hasNext();) {
+ RedstoneTorchBlock.Toggle blockredstonetorch_redstoneupdateinfo = iterator.next();
+ // Paper end
if (blockredstonetorch_redstoneupdateinfo.pos.equals(pos)) {
++i;
if (i >= 8) {