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 <voidsongdragonfly@pm.me>
This commit is contained in:
embeddedt 2025-08-22 20:23:07 -04:00
parent f71277eb64
commit 25976f3b87
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 33 additions and 0 deletions

View File

@ -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();
}
}

View File

@ -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 <init> (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 <init> (Lnet/minecraft/world/level/levelgen/DensityFunctions$Marker$Type;Lnet/minecraft/world/level/levelgen/DensityFunction;)V