diff options
Diffstat (limited to 'patches/server/0235-Optimize-CraftBlockData-Creation.patch')
-rw-r--r-- | patches/server/0235-Optimize-CraftBlockData-Creation.patch | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/patches/server/0235-Optimize-CraftBlockData-Creation.patch b/patches/server/0235-Optimize-CraftBlockData-Creation.patch new file mode 100644 index 0000000000..8f037e052a --- /dev/null +++ b/patches/server/0235-Optimize-CraftBlockData-Creation.patch @@ -0,0 +1,49 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: miclebrick <[email protected]> +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/world/level/block/state/BlockBehaviour.java b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java +index 4ac248f9f5f4f7aa95ddd6e3c3dab1ce94e73d66..d02f7a547dbe8943f82c07103b1fff203e4533c2 100644 +--- a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java ++++ b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java +@@ -813,6 +813,14 @@ public abstract class BlockBehaviour implements FeatureElement { + this.instrument = blockbase_info.instrument; + this.replaceable = blockbase_info.replaceable; + } ++ // Paper start - Perf: impl cached craft block data, lazy load to fix issue with loading at the wrong time ++ private org.bukkit.craftbukkit.block.data.CraftBlockData cachedCraftBlockData; ++ ++ public org.bukkit.craftbukkit.block.data.CraftBlockData createCraftBlockData() { ++ if (cachedCraftBlockData == null) cachedCraftBlockData = org.bukkit.craftbukkit.block.data.CraftBlockData.createData(asState()); ++ return (org.bukkit.craftbukkit.block.data.CraftBlockData) cachedCraftBlockData.clone(); ++ } ++ // Paper end - Perf: impl cached craft block data, lazy load to fix issue with loading at the wrong time + + private boolean calculateSolid() { + if (((Block) this.owner).properties.forceSolidOn) { +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 6ff5da6fac47f5eb6e574665110c0f2649b842d3..c1c5750dd2e4a9af1a115996a87eaaa1ea552c74 100644 +--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java ++++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java +@@ -570,7 +570,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.BLOCK_STATE_REGISTRY.iterator().forEachRemaining(net.minecraft.world.level.block.state.BlockState::createCraftBlockData); ++ } + public static CraftBlockData fromData(net.minecraft.world.level.block.state.BlockState data) { ++ return data.createCraftBlockData(); ++ } ++ ++ public static CraftBlockData createData(net.minecraft.world.level.block.state.BlockState data) { ++ // Paper end + return CraftBlockData.MAP.getOrDefault(data.getBlock().getClass(), CraftBlockData::new).apply(data); + } + |