-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge changes in ver/1.20.4 & opt/tracking
- Loading branch information
1 parent
2e32ca3
commit 69bfa16
Showing
43 changed files
with
480 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
patches/server/0054-SparklyPaper-Skip-distanceToSqr-call-in-ServerEntity.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: MrPowerGamerBR <[email protected]> | ||
Date: Wed, 15 Nov 2023 23:39:36 -0300 | ||
Subject: [PATCH] SparklyPaper: Skip "distanceToSqr" call in | ||
"ServerEntity#sendChanges" if the delta movement hasn't changed | ||
|
||
Original project: https://github.com/SparklyPower/SparklyPaper | ||
|
||
The "distanceToSqr" call is a bit expensive, so avoiding it is pretty nice, around ~15% calls are skipped with this check | ||
|
||
We could also check if the x,y,z coordinates are equal, but for now, let's just keep the identity check, which also helps us since Minecraft's code does reuse the original delta movement Vec3 object | ||
|
||
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java | ||
index fb93f3400ac693f28fb25e5d370d0f6dae8e120a..5a17ccd4a620f17c6434f457244ae2b790e2f34e 100644 | ||
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java | ||
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java | ||
@@ -230,12 +230,14 @@ public class ServerEntity { | ||
|
||
if ((this.trackDelta || this.entity.hasImpulse || this.entity instanceof LivingEntity && ((LivingEntity) this.entity).isFallFlying()) && this.tickCount > 0) { | ||
Vec3 vec3d1 = this.entity.getDeltaMovement(); | ||
+ if (vec3d1 != this.ap) { // SparklyPaper start - skip distanceToSqr call in ServerEntity#sendChanges if the delta movement hasn't changed | ||
double d0 = vec3d1.distanceToSqr(this.ap); | ||
|
||
if (d0 > 1.0E-7D || d0 > 0.0D && vec3d1.lengthSqr() == 0.0D) { | ||
this.ap = vec3d1; | ||
this.broadcast.accept(new ClientboundSetEntityMotionPacket(this.entity.getId(), this.ap)); | ||
} | ||
+ } // SparklyPaper end | ||
} | ||
|
||
if (packet1 != null) { |
138 changes: 138 additions & 0 deletions
138
patches/server/0056-SparklyPaper-Skip-EntityScheduler-s-executeTick-chec.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: MrPowerGamerBR <[email protected]> | ||
Date: Sun, 19 Nov 2023 12:35:16 -0300 | ||
Subject: [PATCH] SparklyPaper: Skip EntityScheduler's executeTick checks if | ||
there isn't any tasks to be run | ||
|
||
Original project: https://github.com/SparklyPower/SparklyPaper | ||
|
||
On each tick, Paper runs EntityScheduler's executeTick of each entity. This is a bit expensive, due to ArrayDeque's size() call because it ain't a simple "get the current queue size" function, due to the thread checks, and because it needs to iterate all entities in all worlds. | ||
|
||
To avoid the hefty ArrayDeque's size() call, we check if we *really* need to execute the executeTick, by adding all entities with scheduled tasks to a global set. | ||
|
||
Most entities won't have any scheduled tasks, so this is a nice performance bonus. These optimizations, however, wouldn't work in a Folia environment, but because in SparklyPaper executeTick is always executed on the main thread, it ain't an issue for us (yay). | ||
|
||
diff --git a/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java b/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java | ||
index 62484ebf4550b05182f693a3180bbac5d5fd906d..67800e426445060a8343e27a7452b8d7ed27ac5f 100644 | ||
--- a/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java | ||
+++ b/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java | ||
@@ -36,6 +36,7 @@ public final class EntityScheduler { | ||
* The Entity. Note that it is the CraftEntity, since only that class properly tracks world transfers. | ||
*/ | ||
public final CraftEntity entity; | ||
+ public final net.minecraft.server.MinecraftServer server; // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run | ||
|
||
private static final record ScheduledTask(Consumer<? extends Entity> run, Consumer<? extends Entity> retired) {} | ||
|
||
@@ -46,7 +47,8 @@ public final class EntityScheduler { | ||
|
||
private final ArrayDeque<ScheduledTask> currentlyExecuting = new ArrayDeque<>(); | ||
|
||
- public EntityScheduler(final CraftEntity entity) { | ||
+ public EntityScheduler(final net.minecraft.server.MinecraftServer server, final CraftEntity entity) { // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run | ||
+ this.server = Validate.notNull(server); | ||
this.entity = Validate.notNull(entity); | ||
} | ||
|
||
@@ -61,14 +63,16 @@ public final class EntityScheduler { | ||
* @throws IllegalStateException If the scheduler is already retired. | ||
*/ | ||
public void retire() { | ||
+ final Entity thisEntity = this.entity.getHandleRaw(); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run | ||
synchronized (this.stateLock) { | ||
if (this.tickCount == RETIRED_TICK_COUNT) { | ||
throw new IllegalStateException("Already retired"); | ||
} | ||
this.tickCount = RETIRED_TICK_COUNT; | ||
+ this.server.entitiesWithScheduledTasks.remove(thisEntity); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run | ||
} | ||
|
||
- final Entity thisEntity = this.entity.getHandleRaw(); | ||
+ // final Entity thisEntity = this.entity.getHandleRaw(); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run (moved up) | ||
|
||
// correctly handle and order retiring while running executeTick | ||
for (int i = 0, len = this.currentlyExecuting.size(); i < len; ++i) { | ||
@@ -124,6 +128,7 @@ public final class EntityScheduler { | ||
if (this.tickCount == RETIRED_TICK_COUNT) { | ||
return false; | ||
} | ||
+ this.server.entitiesWithScheduledTasks.add(this.entity.getHandleRaw()); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run | ||
this.oneTimeDelayed.computeIfAbsent(this.tickCount + Math.max(1L, delay), (final long keyInMap) -> { | ||
return new ArrayList<>(); | ||
}).add(task); | ||
@@ -143,6 +148,13 @@ public final class EntityScheduler { | ||
TickThread.ensureTickThread(thisEntity, "May not tick entity scheduler asynchronously"); | ||
final List<ScheduledTask> toRun; | ||
synchronized (this.stateLock) { | ||
+ // SparklyPaper start - skip EntityScheduler's executeTick checks if there isn't any tasks to be run | ||
+ // Do we *really* have scheduled tasks tho? | ||
+ if (this.currentlyExecuting.isEmpty() && this.oneTimeDelayed.isEmpty()) { // Check if we have any pending tasks and, if not, skip! | ||
+ this.server.entitiesWithScheduledTasks.remove(thisEntity); // We don't! Bye bye!! | ||
+ return; | ||
+ } | ||
+ // SparklyPaper end | ||
if (this.tickCount == RETIRED_TICK_COUNT) { | ||
throw new IllegalStateException("Ticking retired scheduler"); | ||
} | ||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java | ||
index 3e150865ba40413a9caf5e92cd6c4d60debb59da..b6ad776a0a1bc9f7bd25fa665633a75ac500544c 100644 | ||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java | ||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java | ||
@@ -304,6 +304,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa | ||
public volatile boolean abnormalExit = false; // Paper | ||
public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation | ||
|
||
+ public final Set<Entity> entitiesWithScheduledTasks = java.util.concurrent.ConcurrentHashMap.newKeySet(); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run (concurrent because plugins may schedule tasks async) | ||
+ | ||
public gg.pufferfish.pufferfish.util.AsyncExecutor mobSpawnExecutor = new gg.pufferfish.pufferfish.util.AsyncExecutor("pufferfish-async-mob-spawning"); // Pufferfish - optimize mob spawning // Leaf - Unify thread name | ||
|
||
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) { | ||
@@ -1703,6 +1705,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa | ||
this.server.getScheduler().mainThreadHeartbeat(this.tickCount); // CraftBukkit | ||
// Paper start - Folia scheduler API | ||
((io.papermc.paper.threadedregions.scheduler.FoliaGlobalRegionScheduler) Bukkit.getGlobalRegionScheduler()).tick(); | ||
+ // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run | ||
+ for (final Entity entity : entitiesWithScheduledTasks) { | ||
+ if (entity.isRemoved()) { | ||
+ continue; | ||
+ } | ||
+ | ||
+ final org.bukkit.craftbukkit.entity.CraftEntity bukkit = entity.getBukkitEntityRaw(); | ||
+ if (bukkit != null) { | ||
+ bukkit.taskScheduler.executeTick(); | ||
+ } | ||
+ } | ||
+ /* | ||
getAllLevels().forEach(level -> { | ||
for (final Entity entity : level.getEntityLookup().getAllCopy()) { // Paper - rewrite chunk system | ||
if (entity.isRemoved()) { | ||
@@ -1714,6 +1728,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa | ||
} | ||
} | ||
}); | ||
+ */ | ||
+ // SparklyPaper end | ||
// Paper end - Folia scheduler API | ||
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.CALLBACK_MANAGER.handleQueue(this.tickCount); // Paper | ||
this.getFunctions().tick(); | ||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java | ||
index 0ed18542fd8e2a992dc56a5f421eaa840e0af193..833630b65b5ed02ba9a2ee0b73d784b16048e63c 100644 | ||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java | ||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java | ||
@@ -69,7 +69,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { | ||
private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(CraftEntity.DATA_TYPE_REGISTRY); | ||
protected net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers | ||
// Paper start - Folia shedulers | ||
- public final io.papermc.paper.threadedregions.EntityScheduler taskScheduler = new io.papermc.paper.threadedregions.EntityScheduler(this); | ||
+ public final io.papermc.paper.threadedregions.EntityScheduler taskScheduler; // = new io.papermc.paper.threadedregions.EntityScheduler(this); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run | ||
private final io.papermc.paper.threadedregions.scheduler.FoliaEntityScheduler apiScheduler = new io.papermc.paper.threadedregions.scheduler.FoliaEntityScheduler(this); | ||
|
||
@Override | ||
@@ -82,6 +82,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { | ||
this.server = server; | ||
this.entity = entity; | ||
this.entityType = CraftEntityType.minecraftToBukkit(entity.getType()); | ||
+ this.taskScheduler = new io.papermc.paper.threadedregions.EntityScheduler(this.entity.getServer(), this); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run | ||
} | ||
|
||
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
69bfa16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉