From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martin Panzer 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 index a617c69054523dda56b78f175fc8b9c134b60ae2..7c977fad2084a849266caf8e424d0e8e24e8626f 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java @@ -176,6 +176,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { private org.spigotmc.TickLimiter tileLimiter; private int tileTickPosition; public final Map explosionDensityCache = new HashMap<>(); // Paper - Optimize explosions + public java.util.ArrayDeque redstoneUpdateInfos; // Paper - Faster redstone torch rapid clock removal; Move from Map in BlockRedstoneTorch to here 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 index 68da47c3ec59518a4bbeb03c196ef0e7c6b5d049..1dbfda52a4423fb031eecad24e5766f49ecf6050 100644 --- a/src/main/java/net/minecraft/world/level/block/RedstoneTorchBlock.java +++ b/src/main/java/net/minecraft/world/level/block/RedstoneTorchBlock.java @@ -24,7 +24,7 @@ public class RedstoneTorchBlock extends BaseTorchBlock { public static final MapCodec CODEC = simpleCodec(RedstoneTorchBlock::new); public static final BooleanProperty LIT = BlockStateProperties.LIT; - private static final Map> RECENT_TOGGLES = new WeakHashMap(); + // Paper - Faster redstone torch rapid clock removal; Move the mapped list to World public static final int RECENT_TOGGLE_TIMER = 60; public static final int MAX_RECENT_TOGGLES = 8; public static final int RESTART_DELAY = 160; @@ -80,11 +80,15 @@ public class RedstoneTorchBlock extends BaseTorchBlock { @Override public void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) { boolean flag = this.hasNeighborSignal(world, pos, state); - 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 - Faster redstone torch rapid clock removal + java.util.ArrayDeque redstoneUpdateInfos = world.redstoneUpdateInfos; + if (redstoneUpdateInfos != null) { + RedstoneTorchBlock.Toggle curr; + while ((curr = redstoneUpdateInfos.peek()) != null && world.getGameTime() - curr.when > 60L) { + redstoneUpdateInfos.poll(); + } } + // Paper end - Faster redstone torch rapid clock removal // CraftBukkit start org.bukkit.plugin.PluginManager manager = world.getCraftServer().getPluginManager(); @@ -160,9 +164,12 @@ public class RedstoneTorchBlock extends BaseTorchBlock { } private static boolean isToggledTooFrequently(Level world, BlockPos pos, boolean addNew) { - List list = (List) RedstoneTorchBlock.RECENT_TOGGLES.computeIfAbsent(world, (iblockaccess) -> { - return Lists.newArrayList(); - }); + // Paper start - Faster redstone torch rapid clock removal + java.util.ArrayDeque list = world.redstoneUpdateInfos; + if (list == null) { + list = world.redstoneUpdateInfos = new java.util.ArrayDeque<>(); + } + // Paper end - Faster redstone torch rapid clock removal if (addNew) { list.add(new RedstoneTorchBlock.Toggle(pos.immutable(), world.getGameTime()));