From a271feefae371feef2bf008bbceea86138d763f0 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sun, 5 Dec 2021 13:58:01 -0800 Subject: [PATCH] Add dropped hunk from mid-tick tasks (#7034) --- ...ush-calls-for-entity-tracker-packets.patch | 4 ++-- .../server/Execute-chunk-tasks-mid-tick.patch | 20 +++++++++++++++++++ patches/server/MC-Utils.patch | 2 +- .../Optimise-chunk-tick-iteration.patch | 4 ++-- todo.txt | 19 ------------------ 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/patches/server/Consolidate-flush-calls-for-entity-tracker-packets.patch b/patches/server/Consolidate-flush-calls-for-entity-tracker-packets.patch index 8c34db1f90..1948c9649a 100644 --- a/patches/server/Consolidate-flush-calls-for-entity-tracker-packets.patch +++ b/patches/server/Consolidate-flush-calls-for-entity-tracker-packets.patch @@ -26,8 +26,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java +++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java @@ -0,0 +0,0 @@ public class ServerChunkCache extends ChunkSource { - }); - gameprofilerfiller.pop(); + + // Paper - no, iterating just ONCE is expensive enough! Don't do it TWICE! Code moved up gameprofilerfiller.pop(); + // Paper start - controlled flush for entity tracker packets + List disabledFlushes = new java.util.ArrayList<>(this.level.players.size()); diff --git a/patches/server/Execute-chunk-tasks-mid-tick.patch b/patches/server/Execute-chunk-tasks-mid-tick.patch index fd44bf3429..d9634705f3 100644 --- a/patches/server/Execute-chunk-tasks-mid-tick.patch +++ b/patches/server/Execute-chunk-tasks-mid-tick.patch @@ -107,6 +107,26 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 return true; } else { if (this.haveTime()) { +diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java ++++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java +@@ -0,0 +0,0 @@ public class ServerChunkCache extends ChunkSource { + iterator1 = shuffled.iterator(); + } + ++ int chunksTicked = 0; // Paper + try { + while (iterator1.hasNext()) { + LevelChunk chunk1 = iterator1.next(); +@@ -0,0 +0,0 @@ public class ServerChunkCache extends ChunkSource { + + if (this.level.shouldTickBlocksAt(chunkcoordintpair.toLong())) { + this.level.tickChunk(chunk1, k); ++ if ((chunksTicked++ & 1) == 0) net.minecraft.server.MinecraftServer.getServer().executeMidTickTasks(); // Paper + } + } + // Paper start - optimise chunk tick iteration diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/level/ServerLevel.java diff --git a/patches/server/MC-Utils.patch b/patches/server/MC-Utils.patch index b8121ff30e..dd49540c0e 100644 --- a/patches/server/MC-Utils.patch +++ b/patches/server/MC-Utils.patch @@ -6528,7 +6528,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start + public final com.destroystokyo.paper.util.maplist.EntityList entities = new com.destroystokyo.paper.util.maplist.EntityList(); -+ public ChunkHolder playerChunk; ++ public @Nullable ChunkHolder playerChunk; + + static final int NEIGHBOUR_CACHE_RADIUS = 3; + public static int getNeighbourCacheRadius() { diff --git a/patches/server/Optimise-chunk-tick-iteration.patch b/patches/server/Optimise-chunk-tick-iteration.patch index ceaf0f7752..cfeb64101c 100644 --- a/patches/server/Optimise-chunk-tick-iteration.patch +++ b/patches/server/Optimise-chunk-tick-iteration.patch @@ -102,5 +102,5 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 - gameprofilerfiller.pop(); + // Paper - no, iterating just ONCE is expensive enough! Don't do it TWICE! Code moved up gameprofilerfiller.pop(); - // Paper start - controlled flush for entity tracker packets - List disabledFlushes = new java.util.ArrayList<>(this.level.players.size()); + this.chunkMap.tick(); + } diff --git a/todo.txt b/todo.txt index d60d21a98d..10e952eda4 100644 --- a/todo.txt +++ b/todo.txt @@ -4,27 +4,8 @@ Improve Server Thread Pool and Thread Priorities: mojang added a max thread coun Use Vanilla Minecart Speeds: is this needed? 0467-Optimize-WorldBorder-collision-checks-and-air check first hunk that has been removed -Not sure where this needs to go, if anywhere -diff --git a/src/main/java/net/minecraft/world/phys/shapes/Shapes.java b/src/main/java/net/minecraft/world/phys/shapes/Shapes.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/world/phys/shapes/Shapes.java -+++ b/src/main/java/net/minecraft/world/phys/shapes/Shapes.java -@@ -0,0 +0,0 @@ public final class Shapes { - - if (s < 3) { - mutableBlockPos.set(axisCycle, q, r, p); -- BlockState blockState = world.getBlockState(mutableBlockPos); -+ BlockState blockState = world.getTypeIfLoaded(mutableBlockPos); // Paper -+ if (blockState == null) return 0.0D; // Paper - if ((s != 1 || blockState.hasLargeCollisionShape()) && (s != 2 || blockState.is(Blocks.MOVING_PISTON))) { - initial = blockState.getCollisionShape(world, mutableBlockPos, context).collide(axis3, box.move((double)(-mutableBlockPos.getX()), (double)(-mutableBlockPos.getY()), (double)(-mutableBlockPos.getZ())), initial); - if (Math.abs(initial) < 1.0E-7D) { - - - check ChunkHolder#updateFutures async catcher -leaf: check mid tick chunk task diff in ServerChunkCache optimize nearby player lookups - look at patch and updateranges diff in chunkmap (why is it in this patch) GENERAL_AREA_MAP_ACCEPTABLE_SEARCH_RANGE_SQUARED is unused?