3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 19:10:09 +01:00
Paper/Spigot-Server-Patches/0472-Remove-streams-from-PairedQueue.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

83 Zeilen
3.0 KiB
Diff

From 5845b578162a1f609e1e6a9cc604f29fb0a17ddb Mon Sep 17 00:00:00 2001
From: Spottedleaf <spottedleaf@spottedleaf.dev>
Date: Mon, 6 Apr 2020 18:10:43 -0700
Subject: [PATCH] Remove streams from PairedQueue
We shouldn't be doing stream calls just to see if the queue is
empty. This creates loads of garbage thanks to how often it's called.
diff --git a/src/main/java/net/minecraft/server/PairedQueue.java b/src/main/java/net/minecraft/server/PairedQueue.java
index 85bb22e4b73..2369afb4f37 100644
--- a/src/main/java/net/minecraft/server/PairedQueue.java
+++ b/src/main/java/net/minecraft/server/PairedQueue.java
@@ -20,32 +20,30 @@ public interface PairedQueue<T, F> {
public static final class a implements PairedQueue<PairedQueue.b, Runnable> {
- private final List<Queue<Runnable>> a;
+ private final List<Queue<Runnable>> a; private final List<Queue<Runnable>> getQueues() { return this.a; } // Paper - OBFHELPER
public a(int i) {
- this.a = (List) IntStream.range(0, i).mapToObj((j) -> {
- return Queues.newConcurrentLinkedQueue();
- }).collect(Collectors.toList());
+ // Paper start - remove streams
+ this.a = new java.util.ArrayList<>(i); // queues
+ for (int j = 0; j < i; ++j) {
+ this.getQueues().add(Queues.newConcurrentLinkedQueue());
+ }
+ // Paper end - remove streams
}
@Nullable
@Override
public Runnable a() {
- Iterator iterator = this.a.iterator();
-
- Runnable runnable;
-
- do {
- if (!iterator.hasNext()) {
- return null;
+ // Paper start - remove iterator creation
+ for (int i = 0, len = this.getQueues().size(); i < len; ++i) {
+ Queue<Runnable> queue = this.getQueues().get(i);
+ Runnable ret = queue.poll();
+ if (ret != null) {
+ return ret;
}
-
- Queue<Runnable> queue = (Queue) iterator.next();
-
- runnable = (Runnable) queue.poll();
- } while (runnable == null);
-
- return runnable;
+ }
+ return null;
+ // Paper end - remove iterator creation
}
public boolean a(PairedQueue.b pairedqueue_b) {
@@ -57,7 +55,16 @@ public interface PairedQueue<T, F> {
@Override
public boolean b() {
- return this.a.stream().allMatch(Collection::isEmpty);
+ // Paper start - remove streams
+ // why are we doing streams every time we might want to execute a task?
+ for (int i = 0, len = this.getQueues().size(); i < len; ++i) {
+ Queue<Runnable> queue = this.getQueues().get(i);
+ if (!queue.isEmpty()) {
+ return false;
+ }
+ }
+ return true;
+ // Paper end - remove streams
}
}
--
2.26.2