Paper/Spigot-Server-Patches/0342-Optimize-CraftBlockData-Creation.patch
Aikar 835bc39b03
Paper 1.13.1 Update
Updated Upstream (Bukkit/CraftBukkit/Spigot)

Bukkit Changes:
2dcc44dc SPIGOT-4307: Fix hacky API for banners on shields
e0fc6572 SPIGOT-4309: Add "forced" display of particles
efeeab2f Add index to README.md for easier navigation
f502bc6f Update to Minecraft 1.13.1

CraftBukkit Changes:
d0bb0a1d Fix some tests randomly failing
997d378d Fix client stall in specific teleportation scenarios
b3dc2366 SPIGOT-4307: Fix hacky API for banners on shields
2a271162 SPIGOT-4301: Fix more invalid enchants
5d0d83bb SPIGOT-4309: Add "forced" display of particles
a6772578 Add additional tests for CraftBlockData
ce1af0c3 Update to Minecraft 1.13.1

Spigot Changes:
2440e189 Rebuild patches
4ecffced Update to Minecraft 1.13.1
2018-08-26 20:51:39 -04:00

74 lines
3.0 KiB
Diff

From 60322b509f65a591ad5dcce5985e6895cd7b26bc Mon Sep 17 00:00:00 2001
From: miclebrick <miclebrick@outlook.com>
Date: Thu, 23 Aug 2018 11:45:32 -0400
Subject: [PATCH] Optimize CraftBlockData Creation
Avoids a hashmap lookup by cacheing a reference to the CraftBlockData
and cloning it when one is needed.
diff --git a/src/main/java/net/minecraft/server/BlockData.java b/src/main/java/net/minecraft/server/BlockData.java
index 4dd6c32761..1b226a77e0 100644
--- a/src/main/java/net/minecraft/server/BlockData.java
+++ b/src/main/java/net/minecraft/server/BlockData.java
@@ -1,6 +1,7 @@
package net.minecraft.server;
import com.google.common.collect.ImmutableMap;
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
public class BlockData extends BlockDataAbstract<Block, IBlockData> implements IBlockData {
@@ -11,4 +12,14 @@ public class BlockData extends BlockDataAbstract<Block, IBlockData> implements I
public Block getBlock() {
return (Block) this.e_;
}
+
+ // Paper start - impl cached craft block data, lazy load to fix issue with loading at the wrong time
+ private CraftBlockData cachedCraftBlockData;
+
+ @Override
+ public CraftBlockData createCraftBlockData() {
+ if(cachedCraftBlockData == null) cachedCraftBlockData = CraftBlockData.createData(this);
+ return (CraftBlockData) cachedCraftBlockData.clone();
+ }
+ // Paper end
}
diff --git a/src/main/java/net/minecraft/server/IBlockData.java b/src/main/java/net/minecraft/server/IBlockData.java
index 6f80876990..726b178fd8 100644
--- a/src/main/java/net/minecraft/server/IBlockData.java
+++ b/src/main/java/net/minecraft/server/IBlockData.java
@@ -28,6 +28,8 @@ public interface IBlockData extends IBlockDataHolder<IBlockData> {
Block getBlock();
+ org.bukkit.craftbukkit.block.data.CraftBlockData createCraftBlockData(); // Paper - property for converting IBlockData to CraftBlockData, should only be used by CraftBlockData#fromData and should return a clone
+
default Material getMaterial() {
return this.getBlock().n(this);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
index d470e2b34a..b9279d925c 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
@@ -501,7 +501,17 @@ public class CraftBlockData implements BlockData {
return craft;
}
+ // Paper start - optimize creating BlockData to not need a map lookup
+ static {
+ // Initialize cached data for all IBlockData instances after registration
+ Block.REGISTRY_ID.iterator().forEachRemaining(IBlockData::createCraftBlockData);
+ }
public static CraftBlockData fromData(IBlockData data) {
+ return data.createCraftBlockData();
+ }
+
+ public static CraftBlockData createData(IBlockData data) {
+ // Paper end
return MAP.getOrDefault(data.getBlock().getClass(), CraftBlockData::new).apply(data);
}
}
--
2.18.0