From ddbf7318b241a3dd7d4f14b6af1eeb0c399a5a63 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/0042-Misc-Utils.patch | 46 +++++++++++++++++++ .../0181-Optimize-Network-Queue.patch | 22 +++++++++ 2 files changed, 68 insertions(+) create mode 100644 Spigot-API-Patches/0042-Misc-Utils.patch create mode 100644 Spigot-Server-Patches/0181-Optimize-Network-Queue.patch diff --git a/Spigot-API-Patches/0042-Misc-Utils.patch b/Spigot-API-Patches/0042-Misc-Utils.patch new file mode 100644 index 000000000..09729d189 --- /dev/null +++ b/Spigot-API-Patches/0042-Misc-Utils.patch @@ -0,0 +1,46 @@ +From 37bc40ae29d91e8f1f7ffc1ad83b6f3987c16515 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 0000000..d60ecbb +--- /dev/null ++++ b/src/main/java/com/destroystokyo/paper/utils/CachedSizeConcurrentLinkedQueue.java +@@ -0,0 +1,31 @@ ++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(); ++ } ++} +-- +2.8.3.windows.1 + diff --git a/Spigot-Server-Patches/0181-Optimize-Network-Queue.patch b/Spigot-Server-Patches/0181-Optimize-Network-Queue.patch new file mode 100644 index 000000000..5921bf753 --- /dev/null +++ b/Spigot-Server-Patches/0181-Optimize-Network-Queue.patch @@ -0,0 +1,22 @@ +From 43efcd35598c5cfcfec9845b843c7a3ce1380b20 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 683ace3..b4adf7e 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -102,7 +102,7 @@ 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(); + +-- +2.8.3.windows.1 +