Optimize GameRules to use LinkedHashMap

Previously TreeMap was used which has poor get(K) performance.
This commit is contained in:
Spottedleaf 2019-04-04 18:13:49 -07:00
parent 29399ffc02
commit 0891f63203
2 changed files with 87 additions and 1 deletions

View file

@ -18,7 +18,7 @@ index bcb4b5e5c..c399bdecc 100644
public static <C extends WorldGenFeatureConfiguration> WorldGenCarverWrapper<C> a(WorldGenCarver<C> worldgencarver, C c0) {
diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java
index bd2a67cfc..330f5d0c1 100644
index 16bca7942..13dc7abc5 100644
--- a/src/main/java/net/minecraft/server/BlockPosition.java
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
@@ -0,0 +0,0 @@ import org.apache.logging.log4j.Logger;
@ -146,6 +146,28 @@ index 66b168396..83db94c4a 100644
}
public Iterator<IBlockData> iterator() {
diff --git a/src/main/java/net/minecraft/server/GameRules.java b/src/main/java/net/minecraft/server/GameRules.java
index d954b94c3..fd2a4f1b8 100644
--- a/src/main/java/net/minecraft/server/GameRules.java
+++ b/src/main/java/net/minecraft/server/GameRules.java
@@ -0,0 +0,0 @@ import javax.annotation.Nullable;
public class GameRules {
- private static final TreeMap<String, GameRules.GameRuleDefinition> a = (TreeMap) SystemUtils.a((Object) (new TreeMap()), (treemap) -> {
+ private static final TreeMap<String, GameRules.GameRuleDefinition> a = SystemUtils.a(new TreeMap(), (treemap) -> { // Paper - decompile fix
treemap.put("doFireTick", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE));
treemap.put("mobGriefing", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE));
treemap.put("keepInventory", new GameRules.GameRuleDefinition("false", GameRules.EnumGameRuleType.BOOLEAN_VALUE));
@@ -0,0 +0,0 @@ public class GameRules {
private final Supplier<ArgumentType<?>> d;
private final BiFunction<CommandContext<CommandListenerWrapper>, String, String> e;
- private EnumGameRuleType(Supplier supplier, BiFunction bifunction) {
+ private EnumGameRuleType(Supplier supplier, BiFunction<CommandContext<CommandListenerWrapper>, String, String> bifunction) { // Paper - decompile fix
this.d = supplier;
this.e = bifunction;
}
diff --git a/src/main/java/net/minecraft/server/NBTBase.java b/src/main/java/net/minecraft/server/NBTBase.java
index 1425584ed..b2757aad8 100644
--- a/src/main/java/net/minecraft/server/NBTBase.java

View file

@ -0,0 +1,64 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Thu, 4 Apr 2019 17:55:05 -0700
Subject: [PATCH] Optimize GameRules to use LinkedHashMap
Previously TreeMap was used which has poor get(K) performance.
diff --git a/src/main/java/net/minecraft/server/GameRules.java b/src/main/java/net/minecraft/server/GameRules.java
index fd2a4f1b8c..0bd5e02a28 100644
--- a/src/main/java/net/minecraft/server/GameRules.java
+++ b/src/main/java/net/minecraft/server/GameRules.java
@@ -0,0 +0,0 @@ import javax.annotation.Nullable;
public class GameRules {
- private static final TreeMap<String, GameRules.GameRuleDefinition> a = SystemUtils.a(new TreeMap(), (treemap) -> { // Paper - decompile fix
+ // Paper start - Optimize GameRules
+ private static final int RULES_SIZE = 256;
+
+ private static <K, V> java.util.LinkedHashMap<K, V> linkedMapOf(final int capacity, final TreeMap<K, V> map) {
+ final java.util.LinkedHashMap<K, V> ret = new java.util.LinkedHashMap<>(capacity);
+ ret.putAll(map);
+ return ret;
+ }
+
+ private static final java.util.LinkedHashMap<String, GameRuleDefinition> a = GameRules.linkedMapOf(RULES_SIZE, SystemUtils.a(new TreeMap(), (treemap) -> { // Paper - decompile fix
+ // Paper end
treemap.put("doFireTick", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE));
treemap.put("mobGriefing", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE));
treemap.put("keepInventory", new GameRules.GameRuleDefinition("false", GameRules.EnumGameRuleType.BOOLEAN_VALUE));
@@ -0,0 +0,0 @@ public class GameRules {
treemap.put("doLimitedCrafting", new GameRules.GameRuleDefinition("false", GameRules.EnumGameRuleType.BOOLEAN_VALUE));
treemap.put("maxCommandChainLength", new GameRules.GameRuleDefinition("65536", GameRules.EnumGameRuleType.NUMERICAL_VALUE));
treemap.put("announceAdvancements", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE));
- });
- private final TreeMap<String, GameRules.GameRuleValue> b = new TreeMap();
+ })); // Paper - Optimize GameRules
+ private final java.util.LinkedHashMap<String, GameRuleValue> b = new java.util.LinkedHashMap<>(RULES_SIZE); // Paper - Optimize GameRules
public GameRules() {
Iterator iterator = GameRules.a.entrySet().iterator();
@@ -0,0 +0,0 @@ public class GameRules {
return (GameRules.GameRuleValue) this.b.get(s);
}
- public static TreeMap<String, GameRules.GameRuleDefinition> getGameRules() {
+ public static java.util.LinkedHashMap<String, GameRuleDefinition> getGameRules() { // Paper - Optimize GameRules
return GameRules.a;
}
diff --git a/src/test/java/org/bukkit/GameRuleTest.java b/src/test/java/org/bukkit/GameRuleTest.java
index 1ed0f4cf2b..40edb8d668 100644
--- a/src/test/java/org/bukkit/GameRuleTest.java
+++ b/src/test/java/org/bukkit/GameRuleTest.java
@@ -0,0 +0,0 @@ public class GameRuleTest {
@Test
public void testMinecraftRules() {
- TreeMap<String, GameRules.GameRuleDefinition> minecraftRules = GameRules.getGameRules();
+ Map<String, GameRules.GameRuleDefinition> minecraftRules = GameRules.getGameRules(); // Paper - Optimize GameRules
for (Map.Entry<String, GameRules.GameRuleDefinition> entry : minecraftRules.entrySet()) {
GameRule<?> bukkitRule = GameRule.getByName(entry.getKey());
--