Optimize Network Manager to not need synchronization

Removes synchronization from sending packets
Makes normal packet sends no longer need to be wrapped and queued like it use to work.
Adds more packet queue immunities on top of keep alive to let the following scenarios go out
without delay:
  - Keep Alive
  - Chat
  - Kick
  - All of the packets during the Player Joined World event

Hoping that latter one helps join timeout issues more too for slow connections.

Removes processing packet queue off of main thread
  - for the few cases where it is allowed, order is not necessary nor
    should it even be happening concurrently in first place (handshaking/login/status)

Ensures packets sent asynchronously are dispatched on main thread

This helps ensure safety for ProtocolLib as packet listeners
are commonly accessing world state. This will allow you to schedule
a packet to be sent async, but itll be dispatched sync for packet
listeners to process.

This should solve some deadlock risks

This may provide a decent performance improvement because thread synchronization incurs a cache reset
so by avoiding ever entering a synchronized block, we get to avoid that, and packet sending is a really
hot activity.
This commit is contained in:
Aikar
2020-05-06 05:22:03 -04:00
parent 30d007b163
commit fd5c98a9ef
141 changed files with 604 additions and 505 deletions

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Implement Mob Goal API
diff --git a/pom.xml b/pom.xml
index bc8438ae1a..0c0051f7f2 100644
index bc8438ae1ae..0c0051f7f2a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -0,0 +0,0 @@
@@ -24,7 +24,7 @@ index bc8438ae1a..0c0051f7f2 100644
<repositories>
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java b/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java
new file mode 100644
index 0000000000..d6ee941078
index 00000000000..d6ee9410786
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java
@@ -0,0 +0,0 @@
@@ -359,7 +359,7 @@ index 0000000000..d6ee941078
+}
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/PaperCustomGoal.java b/src/main/java/com/destroystokyo/paper/entity/ai/PaperCustomGoal.java
new file mode 100644
index 0000000000..8e4dc2708d
index 00000000000..8e4dc2708d7
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/PaperCustomGoal.java
@@ -0,0 +0,0 @@
@@ -417,7 +417,7 @@ index 0000000000..8e4dc2708d
+}
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/PaperMobGoals.java b/src/main/java/com/destroystokyo/paper/entity/ai/PaperMobGoals.java
new file mode 100644
index 0000000000..d9df0236e8
index 00000000000..d9df0236e82
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/PaperMobGoals.java
@@ -0,0 +0,0 @@
@@ -659,7 +659,7 @@ index 0000000000..d9df0236e8
+}
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/PaperVanillaGoal.java b/src/main/java/com/destroystokyo/paper/entity/ai/PaperVanillaGoal.java
new file mode 100644
index 0000000000..263e8c65b9
index 00000000000..263e8c65b9e
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/PaperVanillaGoal.java
@@ -0,0 +0,0 @@
@@ -727,7 +727,7 @@ index 0000000000..263e8c65b9
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/util/set/OptimizedSmallEnumSet.java b/src/main/java/com/destroystokyo/paper/util/set/OptimizedSmallEnumSet.java
index 9df0006c1a..b3329c6fcd 100644
index 9df0006c1a2..b3329c6fcd6 100644
--- a/src/main/java/com/destroystokyo/paper/util/set/OptimizedSmallEnumSet.java
+++ b/src/main/java/com/destroystokyo/paper/util/set/OptimizedSmallEnumSet.java
@@ -0,0 +0,0 @@ public final class OptimizedSmallEnumSet<E extends Enum<E>> {
@@ -740,7 +740,7 @@ index 9df0006c1a..b3329c6fcd 100644
+ }
}
diff --git a/src/main/java/net/minecraft/server/PathfinderGoal.java b/src/main/java/net/minecraft/server/PathfinderGoal.java
index 93009d83f0..2dfbecf390 100644
index 93009d83f07..2dfbecf3905 100644
--- a/src/main/java/net/minecraft/server/PathfinderGoal.java
+++ b/src/main/java/net/minecraft/server/PathfinderGoal.java
@@ -0,0 +0,0 @@ public abstract class PathfinderGoal {
@@ -776,7 +776,7 @@ index 93009d83f0..2dfbecf390 100644
this.goalTypes.clear();
this.goalTypes.addAllUnchecked(enumset);
diff --git a/src/main/java/net/minecraft/server/PathfinderGoalSelector.java b/src/main/java/net/minecraft/server/PathfinderGoalSelector.java
index 84d2abbcb9..a68fc11ec6 100644
index 84d2abbcb90..a68fc11ec66 100644
--- a/src/main/java/net/minecraft/server/PathfinderGoalSelector.java
+++ b/src/main/java/net/minecraft/server/PathfinderGoalSelector.java
@@ -0,0 +0,0 @@ public class PathfinderGoalSelector {
@@ -815,7 +815,7 @@ index 84d2abbcb9..a68fc11ec6 100644
return this.d.stream().filter(PathfinderGoalWrapped::g);
}
diff --git a/src/main/java/net/minecraft/server/PathfinderGoalWrapped.java b/src/main/java/net/minecraft/server/PathfinderGoalWrapped.java
index 1b800c558f..dee4e2beac 100644
index 1b800c558f0..dee4e2beacb 100644
--- a/src/main/java/net/minecraft/server/PathfinderGoalWrapped.java
+++ b/src/main/java/net/minecraft/server/PathfinderGoalWrapped.java
@@ -0,0 +0,0 @@ import javax.annotation.Nullable;
@@ -830,7 +830,7 @@ index 1b800c558f..dee4e2beac 100644
public PathfinderGoalWrapped(int i, PathfinderGoal pathfindergoal) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 1647c09756..b89f99a66f 100644
index 1647c09756e..b89f99a66fe 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -0,0 +0,0 @@ public final class CraftServer implements Server {
@@ -847,7 +847,7 @@ index 1647c09756..b89f99a66f 100644
}
diff --git a/src/test/java/com/destroystokyo/paper/entity/ai/VanillaMobGoalTest.java b/src/test/java/com/destroystokyo/paper/entity/ai/VanillaMobGoalTest.java
new file mode 100644
index 0000000000..83d34761d9
index 00000000000..83d34761d91
--- /dev/null
+++ b/src/test/java/com/destroystokyo/paper/entity/ai/VanillaMobGoalTest.java
@@ -0,0 +0,0 @@