From 53bdc0450b8bec68a691938e7fd9af1c65240909 Mon Sep 17 00:00:00 2001 From: vemacs Date: Wed, 23 Nov 2016 13:02:47 -0500 Subject: [PATCH] Optimize network queue by making size() constant-time Idea from @AlfieC --- Spigot-API-Patches/Misc-Utils.patch | 44 +++++++++++++++++++ .../Optimize-Network-Queue.patch | 20 +++++++++ 2 files changed, 64 insertions(+) create mode 100644 Spigot-API-Patches/Misc-Utils.patch create mode 100644 Spigot-Server-Patches/Optimize-Network-Queue.patch diff --git a/Spigot-API-Patches/Misc-Utils.patch b/Spigot-API-Patches/Misc-Utils.patch new file mode 100644 index 0000000000..9cb606da02 --- /dev/null +++ b/Spigot-API-Patches/Misc-Utils.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: vemacs +Date: Wed, 23 Nov 2016 12:53:43 -0500 +Subject: [PATCH] Misc Utils + + +diff --git a/src/main/java/com/destroystokyo/paper/utils/CachedSizeConcurrentLinkedQueue.java b/src/main/java/com/destroystokyo/paper/utils/CachedSizeConcurrentLinkedQueue.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/com/destroystokyo/paper/utils/CachedSizeConcurrentLinkedQueue.java +@@ -0,0 +0,0 @@ ++package com.destroystokyo.paper.utils; ++ ++import java.util.concurrent.ConcurrentLinkedQueue; ++import java.util.concurrent.atomic.LongAdder; ++ ++public class CachedSizeConcurrentLinkedQueue extends ConcurrentLinkedQueue { ++ private final LongAdder cachedSize = new LongAdder(); ++ ++ @Override ++ public boolean add(E e) { ++ boolean result = super.add(e); ++ if (result) { ++ cachedSize.increment(); ++ } ++ return result; ++ } ++ ++ @Override ++ public E poll() { ++ E result = super.poll(); ++ if (result != null) { ++ cachedSize.decrement(); ++ } ++ return result; ++ } ++ ++ @Override ++ public int size() { ++ return cachedSize.intValue(); ++ } ++} +-- \ No newline at end of file diff --git a/Spigot-Server-Patches/Optimize-Network-Queue.patch b/Spigot-Server-Patches/Optimize-Network-Queue.patch new file mode 100644 index 0000000000..e909e60237 --- /dev/null +++ b/Spigot-Server-Patches/Optimize-Network-Queue.patch @@ -0,0 +1,20 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: vemacs +Date: Wed, 23 Nov 2016 12:54:56 -0500 +Subject: [PATCH] Optimize Network Queue + + +diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -0,0 +0,0 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs + private final GameProfileRepository X; + private final UserCache Y; + private long Z; +- protected final Queue> j = new java.util.concurrent.ConcurrentLinkedQueue>(); // Spigot, PAIL: Rename ++ protected final Queue> j = new com.destroystokyo.paper.utils.CachedSizeConcurrentLinkedQueue<>(); // Spigot, PAIL: Rename // Paper - Make size() constant-time + private Thread serverThread; + private long ab = aw(); + +-- \ No newline at end of file