testserver/Spigot-Server-Patches/0120-Use-Optimized-Collecti...

59 lines
2.7 KiB
Diff

From 7243594901602fc375b0f27944699f503bd5f846 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 30 Mar 2016 02:13:24 -0400
Subject: [PATCH] Use Optimized Collections
Swap out CraftBukkit LongObjectHashMap with Long2ObjectOpenHashMap
Swap out Integer key HashMap for a Int2ObjectOpenHashMap For ChunkProviderServer
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 3a1ee86..d112216 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;
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<Chunk> chunks = new LongObjectHashMap<Chunk>() {
+ public Long2ObjectOpenHashMap<Chunk> chunks = new Long2ObjectOpenHashMap<Chunk>() {
@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..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<Class<? extends Entity>, Integer> a = Maps.newHashMap();
private final Entity b;
- private final Map<Integer, DataWatcher.Item<?>> c = Maps.newHashMap();
+ private final Map<Integer, DataWatcher.Item<?>> c = new Int2ObjectOpenHashMap<>(); // Paper
private final ReadWriteLock d = new ReentrantReadWriteLock();
private boolean e = true;
private boolean f;
--
2.8.0