Skip to content

Commit 25976f3

Browse files
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 <[email protected]>
1 parent f71277e commit 25976f3

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.embeddedt.modernfix.common.mixin.perf.worldgen_allocation;
2+
3+
import net.minecraft.world.level.levelgen.SurfaceRules;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
6+
@Mixin(targets = {
7+
"net/minecraft/world/level/levelgen/SurfaceRules$BiomeConditionSource$1BiomeCondition",
8+
"net/minecraft/world/level/levelgen/SurfaceRules$StoneDepthCheck$1StoneDepthCondition",
9+
"net/minecraft/world/level/levelgen/SurfaceRules$VerticalGradientConditionSource$1VerticalGradientCondition",
10+
"net/minecraft/world/level/levelgen/SurfaceRules$WaterConditionSource$1WaterCondition",
11+
"net/minecraft/world/level/levelgen/SurfaceRules$YConditionSource$1YCondition",
12+
})
13+
public abstract class SurfaceRulesMixin extends SurfaceRules.LazyCondition {
14+
protected SurfaceRulesMixin(SurfaceRules.Context context) {
15+
super(context);
16+
}
17+
18+
/**
19+
* @author VoidsongDragonfly
20+
* @reason Replacing Vanilla's use of {@link SurfaceRules.LazyYCondition LazyYCondition} that causes performance
21+
* detriments due to unused caching behavior. The `lastUpdateY` field is updated every time the block position
22+
* changes (making the cache useful only within a single block), and the targeted condition objects are not interned
23+
* (meaning there is no caching happening anyway, as each instance uses its own cache).
24+
*
25+
*/
26+
@Override
27+
public boolean test() {
28+
return compute();
29+
}
30+
}

common/src/main/resources/modernfix.accesswidener

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ accessible field net/minecraft/world/level/Level blockEntityTickers Ljava/util/L
1111
accessible class net/minecraft/client/renderer/RenderType$CompositeRenderType
1212
accessible method net/minecraft/nbt/CompoundTag <init> (Ljava/util/Map;)V
1313

14+
accessible class net/minecraft/world/level/levelgen/SurfaceRules$Condition
15+
accessible class net/minecraft/world/level/levelgen/SurfaceRules$LazyCondition
1416
accessible class net/minecraft/world/level/levelgen/SurfaceRules$SequenceRule
1517
accessible class net/minecraft/world/level/levelgen/SurfaceRules$SurfaceRule
18+
accessible class net/minecraft/world/level/levelgen/SurfaceRules$Context
1619
accessible class net/minecraft/world/level/levelgen/DensityFunctions$Marker
1720
accessible class net/minecraft/world/level/levelgen/DensityFunctions$Marker$Type
1821
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

0 commit comments

Comments
 (0)