Paper/Spigot-Server-Patches/0376-ChunkMapDistance-CME.patch
Aikar f37381ea8a
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.
2020-05-06 05:28:47 -04:00

55 lines
2.4 KiB
Diff

From 384ed7ddbd1fb6ee901787fc1b89fd8078bd6421 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Wed, 29 May 2019 04:01:22 +0100
Subject: [PATCH] ChunkMapDistance CME
diff --git a/src/main/java/net/minecraft/server/ChunkMapDistance.java b/src/main/java/net/minecraft/server/ChunkMapDistance.java
index ae661297774..0244768f76d 100644
--- a/src/main/java/net/minecraft/server/ChunkMapDistance.java
+++ b/src/main/java/net/minecraft/server/ChunkMapDistance.java
@@ -33,7 +33,7 @@ public abstract class ChunkMapDistance {
private final ChunkMapDistance.a e = new ChunkMapDistance.a();
private final ChunkMapDistance.b f = new ChunkMapDistance.b(8);
private final ChunkMapDistance.c g = new ChunkMapDistance.c(33);
- private final Set<PlayerChunk> pendingChunkUpdates = Sets.newHashSet();
+ private final java.util.Queue<PlayerChunk> pendingChunkUpdates = new java.util.LinkedList<>(); // PAIL pendingChunkUpdates // Paper - use a queue
private final ChunkTaskQueueSorter i;
private final Mailbox<ChunkTaskQueueSorter.a<Runnable>> j;
private final Mailbox<ChunkTaskQueueSorter.b> k;
@@ -94,26 +94,12 @@ public abstract class ChunkMapDistance {
;
}
+ // Paper start
if (!this.pendingChunkUpdates.isEmpty()) {
- // CraftBukkit start
- // Iterate pending chunk updates with protection against concurrent modification exceptions
- java.util.Iterator<PlayerChunk> iter = this.pendingChunkUpdates.iterator();
- int expectedSize = this.pendingChunkUpdates.size();
- do {
- PlayerChunk playerchunk = iter.next();
- iter.remove();
- expectedSize--;
-
- playerchunk.a(playerchunkmap);
-
- // Reset iterator if set was modified using add()
- if (this.pendingChunkUpdates.size() != expectedSize) {
- expectedSize = this.pendingChunkUpdates.size();
- iter = this.pendingChunkUpdates.iterator();
- }
- } while (iter.hasNext());
- // CraftBukkit end
-
+ while(!this.pendingChunkUpdates.isEmpty()) {
+ this.pendingChunkUpdates.remove().a(playerchunkmap);
+ }
+ // Paper end
return true;
} else {
if (!this.l.isEmpty()) {
--
2.26.2