diff --git a/patches/server/Add-GameEvent-tags.patch b/patches/server/Add-GameEvent-tags.patch index 25fa3c80eb..ed828ce0f4 100644 --- a/patches/server/Add-GameEvent-tags.patch +++ b/patches/server/Add-GameEvent-tags.patch @@ -20,6 +20,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.jetbrains.annotations.NotNull; + ++import java.util.Collections; ++import java.util.IdentityHashMap; ++import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; @@ -30,9 +33,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + super(registry, tag); + } + ++ private static final Map> KEY_CACHE = Collections.synchronizedMap(new IdentityHashMap<>()); + @Override -+ public boolean isTagged(@NotNull GameEvent item) { -+ return registry.getHolderOrThrow(ResourceKey.create(Registry.GAME_EVENT_REGISTRY, CraftNamespacedKey.toMinecraft(item.getKey()))).is(tag); ++ public boolean isTagged(@NotNull GameEvent gameEvent) { ++ return registry.getHolderOrThrow(KEY_CACHE.computeIfAbsent(gameEvent, event -> ResourceKey.create(Registry.GAME_EVENT_REGISTRY, CraftNamespacedKey.toMinecraft(event.getKey())))).is(tag); + } + + @Override diff --git a/patches/server/Add-PaperRegistry.patch b/patches/server/Add-PaperRegistry.patch index 553f47c4a5..def6301a52 100644 --- a/patches/server/Add-PaperRegistry.patch +++ b/patches/server/Add-PaperRegistry.patch @@ -34,6 +34,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import java.util.Map; +import java.util.Objects; +import java.util.Optional; ++import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Supplier; + +@DefaultQualifier(NonNull.class) @@ -49,7 +50,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + private boolean registered; + private final RegistryKey registryKey; + private final Supplier> registry; -+ private final Map cache = new HashMap<>(); ++ private final Map cache = new ConcurrentHashMap<>(); ++ private final Map> resourceKeyCache = new ConcurrentHashMap<>(); + + public PaperRegistry(RegistryKey registryKey) { + this.registryKey = registryKey; @@ -93,7 +95,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + + public Holder getMinecraftHolder(API apiValue) { -+ return this.registry.get().getHolderOrThrow(ResourceKey.create(this.registryKey.resourceKey(), CraftNamespacedKey.toMinecraft(apiValue.getKey()))); ++ return this.registry.get().getHolderOrThrow(this.resourceKeyCache.computeIfAbsent(apiValue.getKey(), key -> ResourceKey.create(this.registryKey.resourceKey(), CraftNamespacedKey.toMinecraft(key)))); + } + + @Override diff --git a/patches/server/cache-resource-keys.patch b/patches/server/cache-resource-keys.patch new file mode 100644 index 0000000000..4fc3eab26c --- /dev/null +++ b/patches/server/cache-resource-keys.patch @@ -0,0 +1,57 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Sun, 20 Mar 2022 22:06:47 -0700 +Subject: [PATCH] cache resource keys + + +diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java ++++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +@@ -0,0 +0,0 @@ public class CraftBlock implements Block { + return (biome == null) ? Biome.CUSTOM : biome; + } + ++ private static final java.util.Map> BIOME_KEY_CACHE = Collections.synchronizedMap(new java.util.EnumMap<>(Biome.class)); // Paper + public static Holder biomeToBiomeBase(net.minecraft.core.Registry registry, Biome bio) { + if (bio == null || bio == Biome.CUSTOM) { + return null; + } + +- return registry.getHolderOrThrow(ResourceKey.create(net.minecraft.core.Registry.BIOME_REGISTRY, CraftNamespacedKey.toMinecraft(bio.getKey()))); ++ return registry.getHolderOrThrow(BIOME_KEY_CACHE.computeIfAbsent(bio, b -> ResourceKey.create(net.minecraft.core.Registry.BIOME_REGISTRY, CraftNamespacedKey.toMinecraft(b.getKey())))); // Paper - cache key + } + + @Override +diff --git a/src/main/java/org/bukkit/craftbukkit/tag/CraftEntityTag.java b/src/main/java/org/bukkit/craftbukkit/tag/CraftEntityTag.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/tag/CraftEntityTag.java ++++ b/src/main/java/org/bukkit/craftbukkit/tag/CraftEntityTag.java +@@ -0,0 +0,0 @@ public class CraftEntityTag extends CraftTag>> KEY_CACHE = Collections.synchronizedMap(new java.util.EnumMap<>(EntityType.class)); // Paper + @Override + public boolean isTagged(EntityType entity) { +- return registry.getHolderOrThrow(ResourceKey.create(net.minecraft.core.Registry.ENTITY_TYPE_REGISTRY, CraftNamespacedKey.toMinecraft(entity.getKey()))).is(tag); ++ return registry.getHolderOrThrow(KEY_CACHE.computeIfAbsent(entity, type -> ResourceKey.create(net.minecraft.core.Registry.ENTITY_TYPE_REGISTRY, CraftNamespacedKey.toMinecraft(type.getKey())))).is(tag); // Paper - cache key + } + + @Override +diff --git a/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java b/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java ++++ b/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java +@@ -0,0 +0,0 @@ public class CraftFluidTag extends CraftTag> KEY_CACHE = Collections.synchronizedMap(new java.util.EnumMap<>(Fluid.class)); // Paper + @Override + public boolean isTagged(Fluid fluid) { +- return registry.getHolderOrThrow(net.minecraft.resources.ResourceKey.create(net.minecraft.core.Registry.FLUID_REGISTRY, org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(fluid.getKey()))).is(tag); // Paper ++ return registry.getHolderOrThrow(KEY_CACHE.computeIfAbsent(fluid, f -> net.minecraft.resources.ResourceKey.create(net.minecraft.core.Registry.FLUID_REGISTRY, org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(f.getKey())))).is(tag); // Paper - cache key + } + + @Override