Implement improved version of LazyDFU (having it installed is still beneficial)
Now DFU classes are not loaded until the first time DFU is actually needed to update something. This saves quite a bit of RAM. This is a better version of dedup_blockstate_flattening_map so the latter is removed.
This commit is contained in:
parent
7039bcada7
commit
c561d818f3
|
|
@ -62,7 +62,6 @@ public class ModernFixEarlyConfig {
|
|||
/* Use a simpler ArrayMap if FerriteCore is using the map intelligently anyway */
|
||||
this.addMixinRule("perf.state_definition_construct", modPresent("ferritecore"));
|
||||
this.addMixinRule("perf.cache_strongholds", true);
|
||||
this.addMixinRule("perf.dedup_blockstate_flattening_map", false);
|
||||
this.addMixinRule("perf.clear_mixin_classinfo", false);
|
||||
this.addMixinRule("perf.cache_upgraded_structures", true);
|
||||
this.addMixinRule("perf.biome_zoomer", true);
|
||||
|
|
@ -93,6 +92,7 @@ public class ModernFixEarlyConfig {
|
|||
this.addMixinRule("perf.nbt_memory_usage", true);
|
||||
this.addMixinRule("perf.patchouli_deduplicate_books", modPresent("patchouli"));
|
||||
this.addMixinRule("perf.datapack_reload_exceptions", true);
|
||||
this.addMixinRule("perf.dynamic_dfu", true);
|
||||
this.addMixinRule("perf.async_locator", true);
|
||||
this.addMixinRule("perf.faster_texture_stitching", true);
|
||||
this.addMixinRule("perf.faster_texture_loading", true);
|
||||
|
|
|
|||
96
src/main/java/org/embeddedt/modernfix/dfu/LazyDataFixer.java
Normal file
96
src/main/java/org/embeddedt/modernfix/dfu/LazyDataFixer.java
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
package org.embeddedt.modernfix.dfu;
|
||||
|
||||
import com.mojang.datafixers.DSL;
|
||||
import com.mojang.datafixers.DataFix;
|
||||
import com.mojang.datafixers.DataFixUtils;
|
||||
import com.mojang.datafixers.DataFixer;
|
||||
import com.mojang.datafixers.schemas.Schema;
|
||||
import com.mojang.datafixers.types.Type;
|
||||
import com.mojang.datafixers.types.constant.EmptyPart;
|
||||
import com.mojang.datafixers.types.templates.TypeTemplate;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import net.minecraft.SharedConstants;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class LazyDataFixer implements DataFixer {
|
||||
private static final Logger LOGGER = LogManager.getLogger("ModernFix");
|
||||
private DataFixer backingDataFixer;
|
||||
private final Supplier<DataFixer> dfuSupplier;
|
||||
private static final Schema FAKE_SCHEMA = new EmptySchema();
|
||||
|
||||
public LazyDataFixer(Supplier<DataFixer> dfuSupplier) {
|
||||
LOGGER.info("Bypassed Mojang DFU");
|
||||
this.backingDataFixer = null;
|
||||
this.dfuSupplier = dfuSupplier;
|
||||
}
|
||||
@Override
|
||||
public <T> Dynamic<T> update(DSL.TypeReference type, Dynamic<T> input, int version, int newVersion) {
|
||||
if(version >= newVersion)
|
||||
return input;
|
||||
synchronized (this) {
|
||||
if(backingDataFixer == null) {
|
||||
LOGGER.info("Instantiating Mojang DFU");
|
||||
backingDataFixer = dfuSupplier.get();
|
||||
}
|
||||
}
|
||||
return backingDataFixer.update(type, input, version, newVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* "getSchema is only there for checks that are not important" - fry, 2021
|
||||
*/
|
||||
@Override
|
||||
public Schema getSchema(int key) {
|
||||
return FAKE_SCHEMA;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty schema that also returns empty Type<?> instances to prevent crashes.
|
||||
*/
|
||||
static class EmptySchema extends Schema {
|
||||
public EmptySchema() {
|
||||
super(DataFixUtils.makeKey(SharedConstants.getCurrentVersion().getWorldVersion()), null);
|
||||
}
|
||||
|
||||
private static final Type<?> EMPTY_TYPE = new EmptyPart();
|
||||
private static final TypeTemplate FAKE_TEMPLATE = EMPTY_TYPE.template();
|
||||
|
||||
|
||||
@Override
|
||||
protected Map<String, Type<?>> buildTypes() {
|
||||
Object2ObjectOpenHashMap<String, Type<?>> map = new Object2ObjectOpenHashMap<>();
|
||||
map.defaultReturnValue(new EmptyPart());
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeTemplate resolveTemplate(String name) {
|
||||
return FAKE_TEMPLATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<?> getChoiceType(DSL.TypeReference type, String choiceName) {
|
||||
return EMPTY_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerTypes(Schema schema, Map<String, Supplier<TypeTemplate>> entityTypes, Map<String, Supplier<TypeTemplate>> blockEntityTypes) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Supplier<TypeTemplate>> registerEntities(Schema schema) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Supplier<TypeTemplate>> registerBlockEntities(Schema schema) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
package org.embeddedt.modernfix.mixin.perf.dedup_blockstate_flattening_map;
|
||||
|
||||
import net.minecraft.util.datafix.fixes.BlockStateData;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(BlockStateData.class)
|
||||
public class BlockStateDataMixin {
|
||||
@Inject(method = {"register", "finalizeMaps"}, at = @At("HEAD"), cancellable = true)
|
||||
private static void noFlattening(CallbackInfo ci) {
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
@Inject(method = {"upgradeBlockStateTag", "upgradeBlock(I)Ljava/lang/String;", "upgradeBlock(Ljava/lang/String;)Ljava/lang/String;", "getTag"}, at = @At("HEAD"), require = 4)
|
||||
private static void preventCorruption(CallbackInfoReturnable<?> cir) {
|
||||
throw new UnsupportedOperationException("Performing the Flattening is currently disabled in the ModernFix config.");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
package org.embeddedt.modernfix.mixin.perf.dedup_blockstate_flattening_map;
|
||||
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.util.datafix.fixes.ChunkPalettedStorageFix;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mixin(ChunkPalettedStorageFix.class)
|
||||
public class ChunkPalettedStorageFixMixin {
|
||||
@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lcom/mojang/datafixers/DataFixUtils;make(Ljava/lang/Object;Ljava/util/function/Consumer;)Ljava/lang/Object;"))
|
||||
private static Object skipMakingMap(Object o, Consumer<?> consumer) {
|
||||
return o;
|
||||
}
|
||||
|
||||
@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/datafix/fixes/BlockStateData;getTag(I)Lcom/mojang/serialization/Dynamic;"))
|
||||
private static Dynamic<?> getFakeAirTag(int id) {
|
||||
return new Dynamic<>(NbtOps.INSTANCE, new CompoundTag());
|
||||
}
|
||||
|
||||
@Inject(method = "fix", at = @At("HEAD"))
|
||||
private void skipFix(CallbackInfoReturnable<Dynamic<?>> cir) {
|
||||
throw new UnsupportedOperationException("No Flattening for you.");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package org.embeddedt.modernfix.mixin.perf.dynamic_dfu;
|
||||
|
||||
import com.mojang.datafixers.DataFixer;
|
||||
import net.minecraft.util.datafix.DataFixers;
|
||||
import org.embeddedt.modernfix.dfu.LazyDataFixer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(DataFixers.class)
|
||||
public abstract class DataFixersMixin {
|
||||
@Shadow protected static DataFixer createFixerUpper() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
private static LazyDataFixer lazyDataFixer;
|
||||
|
||||
/**
|
||||
* Avoid classloading the DFU logic until we actually need it.
|
||||
*/
|
||||
@Inject(method = "createFixerUpper", at = @At("HEAD"), cancellable = true)
|
||||
private static void createLazyFixerUpper(CallbackInfoReturnable<DataFixer> cir) {
|
||||
if(lazyDataFixer == null) {
|
||||
lazyDataFixer = new LazyDataFixer(DataFixersMixin::createFixerUpper);
|
||||
cir.setReturnValue(lazyDataFixer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@
|
|||
"bugfix.chunk_deadlock.ServerChunkCacheMixin",
|
||||
"bugfix.chunk_deadlock.valhesia.BlockStateBaseMixin",
|
||||
"perf.dedicated_reload_executor.MinecraftServerMixin",
|
||||
"perf.dynamic_dfu.DataFixersMixin",
|
||||
"perf.remove_biome_temperature_cache.BiomeMixin",
|
||||
"perf.resourcepacks.ModFileResourcePackMixin",
|
||||
"perf.resourcepacks.VanillaPackMixin",
|
||||
|
|
@ -75,8 +76,6 @@
|
|||
"perf.biome_zoomer.FuzzyOffsetBiomeZoomerMixin",
|
||||
"perf.compress_blockstate.BlockStateBaseMixin",
|
||||
"perf.compress_blockstate.BlockBehaviourMixin",
|
||||
"perf.dedup_blockstate_flattening_map.BlockStateDataMixin",
|
||||
"perf.dedup_blockstate_flattening_map.ChunkPalettedStorageFixMixin",
|
||||
"perf.remove_spawn_chunks.ServerChunkCacheAccessor",
|
||||
"perf.remove_spawn_chunks.MinecraftServerMixin",
|
||||
"perf.remove_spawn_chunks.ServerLevelMixin",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user