From 78202f87b75beabeadc1dbe8c0b1e29f41e6347e Mon Sep 17 00:00:00 2001 From: Aikar Date: Thu, 31 Mar 2016 21:45:30 -0400 Subject: [PATCH] Remove Long2ObjectHashMap for Chunks Speaking with Amaranth, his point of his implementation was that most of the lookups are on loaded chunks, so that code is optimized for that case. While Long2Object should be faster as a general purpose map, for MC uses, Amaranth's version should be faster. Will try to benchmark the 2 at some future. --- ...FastUtil-Int-HashMap-for-DataWatcher.patch | 33 +++++++++++ ...0123-Use-FastUtil-Long-Int-HashMap-s.patch | 56 ------------------- 2 files changed, 33 insertions(+), 56 deletions(-) create mode 100644 Spigot-Server-Patches/0123-Use-FastUtil-Int-HashMap-for-DataWatcher.patch delete mode 100644 Spigot-Server-Patches/0123-Use-FastUtil-Long-Int-HashMap-s.patch diff --git a/Spigot-Server-Patches/0123-Use-FastUtil-Int-HashMap-for-DataWatcher.patch b/Spigot-Server-Patches/0123-Use-FastUtil-Int-HashMap-for-DataWatcher.patch new file mode 100644 index 000000000..821694feb --- /dev/null +++ b/Spigot-Server-Patches/0123-Use-FastUtil-Int-HashMap-for-DataWatcher.patch @@ -0,0 +1,33 @@ +From 4450f745a28e5709f5df9bb18e8347a47370301f 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 f1c62ec..68a0565 100644 +--- a/src/main/java/net/minecraft/server/DataWatcher.java ++++ b/src/main/java/net/minecraft/server/DataWatcher.java +@@ -11,13 +11,14 @@ 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; +-- +2.8.0 + diff --git a/Spigot-Server-Patches/0123-Use-FastUtil-Long-Int-HashMap-s.patch b/Spigot-Server-Patches/0123-Use-FastUtil-Long-Int-HashMap-s.patch deleted file mode 100644 index d14cd0b45..000000000 --- a/Spigot-Server-Patches/0123-Use-FastUtil-Long-Int-HashMap-s.patch +++ /dev/null @@ -1,56 +0,0 @@ -From c12c8e716ed41b8cee8d9f1057d1e138b73d7169 Mon Sep 17 00:00:00 2001 -From: Aikar -Date: Wed, 30 Mar 2016 02:13:24 -0400 -Subject: [PATCH] Use FastUtil Long/Int HashMap's - -For DataWatcher, swap out plain Integer key HashMap for a Int2ObjectOpenHashMap -For ChunkProviderServer, swap out CB's custom LongHashMap with Long2ObjectOpenHashMap - -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 f31ffe2..646197c 100644 ---- a/src/main/java/net/minecraft/server/ChunkProviderServer.java -+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java -@@ -5,6 +5,7 @@ import java.util.Iterator; - import java.util.List; - - import com.destroystokyo.paper.exception.ServerInternalException; -+import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; // Paper - import org.apache.logging.log4j.LogManager; - import org.apache.logging.log4j.Logger; - -@@ -26,7 +27,7 @@ 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 f1c62ec..deb9643 100644 ---- a/src/main/java/net/minecraft/server/DataWatcher.java -+++ b/src/main/java/net/minecraft/server/DataWatcher.java -@@ -11,13 +11,15 @@ 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; --- -2.8.0 -