From 48ba10bc770b2cab7c08a7e44a0824c7c7387103 Mon Sep 17 00:00:00 2001 From: Aikar Date: Tue, 5 Apr 2016 20:43:11 -0400 Subject: [PATCH] Re-add fastutil map to Chunk map. Amaranth confirmed its faster by 3x --- ...FastUtil-Int-HashMap-for-DataWatcher.patch | 31 ----------- .../Use-Optimized-Collections.patch | 55 +++++++++++++++++++ 2 files changed, 55 insertions(+), 31 deletions(-) delete mode 100644 Spigot-Server-Patches/Use-FastUtil-Int-HashMap-for-DataWatcher.patch create mode 100644 Spigot-Server-Patches/Use-Optimized-Collections.patch diff --git a/Spigot-Server-Patches/Use-FastUtil-Int-HashMap-for-DataWatcher.patch b/Spigot-Server-Patches/Use-FastUtil-Int-HashMap-for-DataWatcher.patch deleted file mode 100644 index c1fb818a8f..0000000000 --- a/Spigot-Server-Patches/Use-FastUtil-Int-HashMap-for-DataWatcher.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Aikar -Date: Wed, 30 Mar 2016 02:13:24 -0400 -Subject: [PATCH] Use FastUtil Int HashMap for DataWatcher - -For DataWatcher, swap out plain Integer key HashMap for a Int2ObjectOpenHashMap - -These collections are super fast as seen -http://java-performance.info/hashmap-overview-jdk-fastutil-goldman-sachs-hppc-koloboke-trove-january-2015/ - -diff --git a/src/main/java/net/minecraft/server/DataWatcher.java b/src/main/java/net/minecraft/server/DataWatcher.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/server/DataWatcher.java -+++ b/src/main/java/net/minecraft/server/DataWatcher.java -@@ -0,0 +0,0 @@ import java.util.List; - import java.util.Map; - import java.util.concurrent.locks.ReadWriteLock; - import java.util.concurrent.locks.ReentrantReadWriteLock; -+import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; // Paper - import org.apache.commons.lang3.ObjectUtils; - - public class DataWatcher { - - private static final Map, Integer> a = Maps.newHashMap(); - private final Entity b; -- private final Map> c = Maps.newHashMap(); -+ private final Map> c = new Int2ObjectOpenHashMap<>(); // Paper - private final ReadWriteLock d = new ReentrantReadWriteLock(); - private boolean e = true; - private boolean f; --- \ No newline at end of file diff --git a/Spigot-Server-Patches/Use-Optimized-Collections.patch b/Spigot-Server-Patches/Use-Optimized-Collections.patch new file mode 100644 index 0000000000..c912aa9066 --- /dev/null +++ b/Spigot-Server-Patches/Use-Optimized-Collections.patch @@ -0,0 +1,55 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Wed, 30 Mar 2016 02:13:24 -0400 +Subject: [PATCH] Use Optimized Collections For DataWatcher, swap out plain + Integer key HashMap for a Int2ObjectOpenHashMap For ChunkProviderServer, swap + out CraftBukkit LongObjectHashMap with Long2ObjectOpenHashMap + +Amaranth, the creator of LongObjectHashMap, tested it vs fastutil and determined fastutil to be 3x faster +and could not create anything faster than fastutil. + +These collections are super fast as seen +http://java-performance.info/hashmap-overview-jdk-fastutil-goldman-sachs-hppc-koloboke-trove-january-2015/ + +diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java ++++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java +@@ -0,0 +0,0 @@ import java.util.Iterator; + import java.util.List; + + import com.destroystokyo.paper.exception.ServerInternalException; ++import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; + import org.apache.logging.log4j.LogManager; + import org.apache.logging.log4j.Logger; + +@@ -0,0 +0,0 @@ public class ChunkProviderServer implements IChunkProvider { + private final IChunkLoader chunkLoader; + // Paper start + protected Chunk lastChunkByPos = null; +- public LongObjectHashMap chunks = new LongObjectHashMap() { ++ public Long2ObjectOpenHashMap chunks = new Long2ObjectOpenHashMap() { + @Override + public Chunk get(long key) { + if (lastChunkByPos != null && key == lastChunkByPos.chunkKey) { +diff --git a/src/main/java/net/minecraft/server/DataWatcher.java b/src/main/java/net/minecraft/server/DataWatcher.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/DataWatcher.java ++++ b/src/main/java/net/minecraft/server/DataWatcher.java +@@ -0,0 +0,0 @@ import java.util.List; + import java.util.Map; + import java.util.concurrent.locks.ReadWriteLock; + import java.util.concurrent.locks.ReentrantReadWriteLock; ++import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; // Paper + import org.apache.commons.lang3.ObjectUtils; + + public class DataWatcher { + + private static final Map, Integer> a = Maps.newHashMap(); + private final Entity b; +- private final Map> c = Maps.newHashMap(); ++ private final Map> c = new Int2ObjectOpenHashMap<>(); // Paper + private final ReadWriteLock d = new ReentrantReadWriteLock(); + private boolean e = true; + private boolean f; +-- \ No newline at end of file