Skip to content

Commit

Permalink
Add Mutltithreaded Tracker & Async playerdata aving (#109)
Browse files Browse the repository at this point in the history
* init Multithreaded Tracker

* Rebase & Clean up

* Some clean up

* Some work

* [ci skip] Checked some petal issues

* Fix tracker

* Unify thread name again

* Nitori: Async playerdata Save

* Rebase

* Fix Citizens player type NPC tracking issue (WIP)

Temporary move sendChanges to off-main only. This can fix Citizens's player type NPC visible issue. But still working on making updatePlayer async too, since it also takes big part of performance, and also need to be compat with Citizens.

* [ci skip] Drop useless patch

* [ci skip] Adjust comments

* Optimize tracker, batch processing sendChanges tasks

* Clean up and fix

* Rebase

* Partial update player asynchronously & Fix citizens player type NPC visual issue

This made async tracker compat with CItizens, but still need to further optimize

* Optimize and update config

* Fix realPlayer detect condition & Made more async & Update patch comment

* Add compat mode for tracker

By isolating Citizens compat logic into compat mode, it can gain more performance if Citizens is not installed.

* [ci skip] Update comment
  • Loading branch information
Dreeam-qwq authored Sep 6, 2024
1 parent bd74ab7 commit ee59e06
Show file tree
Hide file tree
Showing 9 changed files with 655 additions and 204 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ If these excellent projects hadn't appeared, Leaf wouldn't have become great.
• <a href="https://github.com/HaHaWTH/Polpot">Polpot</a><br>
• <a href="https://github.com/plasmoapp/matter">Matter</a><br>
• <a href="https://github.com/LuminolMC/Luminol">Luminol</a><br>
• <a href="https://github.com/Gensokyo-Reimagined/Nitori">Nitori</a><br>
</p>
</details>

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions patches/server/0012-Fix-Pufferfish-and-Purpur-patches.patch
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ index 23609a71a993fc91271578ee0a541a9c6ec7354f..34f7f74b374d319d0d578e498db7663d

@Override
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 9d082b3c06281b0cafe455959d6ef20b8891110e..5071828f4ec318ca457d7c29d5ffaa3de2f43e48 100644
index 9d082b3c06281b0cafe455959d6ef20b8891110e..c842bd59cb612a98d261d31a026d4ae8ce4e455b 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -300,7 +300,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
Expand All @@ -45,7 +45,7 @@ index 9d082b3c06281b0cafe455959d6ef20b8891110e..5071828f4ec318ca457d7c29d5ffaa3d
public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation

- public gg.pufferfish.pufferfish.util.AsyncExecutor mobSpawnExecutor = new gg.pufferfish.pufferfish.util.AsyncExecutor("MobSpawning"); // Pufferfish - optimize mob spawning
+ 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 gg.pufferfish.pufferfish.util.AsyncExecutor mobSpawnExecutor = new gg.pufferfish.pufferfish.util.AsyncExecutor("Leaf Async Mob Spawn Thread"); // Pufferfish - optimize mob spawning // Leaf - Unify thread name

public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
AtomicReference<S> atomicreference = new AtomicReference();
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0039-Petal-Async-Pathfinding.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ index 0000000000000000000000000000000000000000..2f5aff1f0e2aca0a8bfeab27c4ab027f
+}
diff --git a/src/main/java/org/dreeam/leaf/async/path/AsyncPathProcessor.java b/src/main/java/org/dreeam/leaf/async/path/AsyncPathProcessor.java
new file mode 100644
index 0000000000000000000000000000000000000000..ccee3723679d3740d34bd13c04018bafafa5da62
index 0000000000000000000000000000000000000000..3eb86fc2e0ea28be18e23dd2c060e043f1fede93
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/async/path/AsyncPathProcessor.java
@@ -0,0 +1,52 @@
Expand Down Expand Up @@ -1123,7 +1123,7 @@ index 0000000000000000000000000000000000000000..ccee3723679d3740d34bd13c04018baf
+ org.dreeam.leaf.config.modules.async.AsyncPathfinding.asyncPathfindingKeepalive, TimeUnit.SECONDS,
+ new LinkedBlockingQueue<>(),
+ new ThreadFactoryBuilder()
+ .setNameFormat("petal-async-pathfinding-thread-%d")
+ .setNameFormat("Leaf Async Pathfinding Thread - %d")
+ .setPriority(Thread.NORM_PRIORITY - 2)
+ .build()
+ );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ index c03608fec96b51e1867f43d8f42e5aefb1520e46..15b21fa3907db1b77ed5b5d1050a37f4
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 efd29f9d2417c9483b0aa2c521109a9e20f6990c..7308c3ae41397338092ab3f7f95baca6b2a515c3 100644
index 55466ff58d724a6254fd6e53c72adb592f2d433a..0255d5a23e2f5a1a67af3ff1588b608521e4c133 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -312,6 +312,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation

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 gg.pufferfish.pufferfish.util.AsyncExecutor mobSpawnExecutor = new gg.pufferfish.pufferfish.util.AsyncExecutor("Leaf Async Mob Spawn Thread"); // Pufferfish - optimize mob spawning // Leaf - Unify thread name
+ 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 static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
Expand Down
Loading

0 comments on commit ee59e06

Please sign in to comment.