From 25976f3b870313502afe20913478090b9faf2f89 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Fri, 22 Aug 2025 20:23:07 -0400 Subject: [PATCH] Disable LazyYCondition logic in situations where it has no effect This saves roughly 10% of time in surface rule evaluation in some tests. Closes #585 Co-authored-by: Voidsong Dragonfly --- .../SurfaceRulesMixin.java | 30 +++++++++++++++++++ .../main/resources/modernfix.accesswidener | 3 ++ 2 files changed, 33 insertions(+) create mode 100644 common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/worldgen_allocation/SurfaceRulesMixin.java diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/worldgen_allocation/SurfaceRulesMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/worldgen_allocation/SurfaceRulesMixin.java new file mode 100644 index 00000000..4635a560 --- /dev/null +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/worldgen_allocation/SurfaceRulesMixin.java @@ -0,0 +1,30 @@ +package org.embeddedt.modernfix.common.mixin.perf.worldgen_allocation; + +import net.minecraft.world.level.levelgen.SurfaceRules; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(targets = { + "net/minecraft/world/level/levelgen/SurfaceRules$BiomeConditionSource$1BiomeCondition", + "net/minecraft/world/level/levelgen/SurfaceRules$StoneDepthCheck$1StoneDepthCondition", + "net/minecraft/world/level/levelgen/SurfaceRules$VerticalGradientConditionSource$1VerticalGradientCondition", + "net/minecraft/world/level/levelgen/SurfaceRules$WaterConditionSource$1WaterCondition", + "net/minecraft/world/level/levelgen/SurfaceRules$YConditionSource$1YCondition", +}) +public abstract class SurfaceRulesMixin extends SurfaceRules.LazyCondition { + protected SurfaceRulesMixin(SurfaceRules.Context context) { + super(context); + } + + /** + * @author VoidsongDragonfly + * @reason Replacing Vanilla's use of {@link SurfaceRules.LazyYCondition LazyYCondition} that causes performance + * detriments due to unused caching behavior. The `lastUpdateY` field is updated every time the block position + * changes (making the cache useful only within a single block), and the targeted condition objects are not interned + * (meaning there is no caching happening anyway, as each instance uses its own cache). + * + */ + @Override + public boolean test() { + return compute(); + } +} diff --git a/common/src/main/resources/modernfix.accesswidener b/common/src/main/resources/modernfix.accesswidener index 57322acc..3cd36b76 100644 --- a/common/src/main/resources/modernfix.accesswidener +++ b/common/src/main/resources/modernfix.accesswidener @@ -11,8 +11,11 @@ accessible field net/minecraft/world/level/Level blockEntityTickers Ljava/util/L accessible class net/minecraft/client/renderer/RenderType$CompositeRenderType accessible method net/minecraft/nbt/CompoundTag (Ljava/util/Map;)V +accessible class net/minecraft/world/level/levelgen/SurfaceRules$Condition +accessible class net/minecraft/world/level/levelgen/SurfaceRules$LazyCondition accessible class net/minecraft/world/level/levelgen/SurfaceRules$SequenceRule accessible class net/minecraft/world/level/levelgen/SurfaceRules$SurfaceRule +accessible class net/minecraft/world/level/levelgen/SurfaceRules$Context accessible class net/minecraft/world/level/levelgen/DensityFunctions$Marker accessible class net/minecraft/world/level/levelgen/DensityFunctions$Marker$Type accessible method net/minecraft/world/level/levelgen/DensityFunctions$Marker (Lnet/minecraft/world/level/levelgen/DensityFunctions$Marker$Type;Lnet/minecraft/world/level/levelgen/DensityFunction;)V