From bbd382d71047a39bfe3fe390dcbd7e6d605c8c97 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Fri, 30 Aug 2024 15:55:33 -0700 Subject: [PATCH] Reuse a single ThreadingDetector instance for all PalettedContainers We make all instance methods on ThreadingDetector no-op already, so no point in keeping multiple instances around. This saves around 100mb in my ATM10 SP world. --- .../PalettedContainerMixin.java | 29 +++++++++++++++++++ src/main/resources/moonrise.mixins.json | 1 + 2 files changed, 30 insertions(+) create mode 100644 src/main/java/ca/spottedleaf/moonrise/mixin/util_threading_detector/PalettedContainerMixin.java diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/util_threading_detector/PalettedContainerMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/util_threading_detector/PalettedContainerMixin.java new file mode 100644 index 00000000..c2b53697 --- /dev/null +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/util_threading_detector/PalettedContainerMixin.java @@ -0,0 +1,29 @@ +package ca.spottedleaf.moonrise.mixin.util_threading_detector; + +import net.minecraft.util.ThreadingDetector; +import net.minecraft.world.level.chunk.PalettedContainer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(PalettedContainer.class) +abstract class PalettedContainerMixin { + @Unique + private static final ThreadingDetector THREADING_DETECTOR = new ThreadingDetector("PalettedContainer"); + + /** + * @reason our ThreadingDetectorMixin makes all instance methods no-op, no use in having multiple instances + * @author jpenilla + */ + @Redirect( + method = "*", + at = @At( + value = "NEW", + target = "Lnet/minecraft/util/ThreadingDetector;" + ) + ) + private static ThreadingDetector threadingDetector(final String name) { + return THREADING_DETECTOR; + } +} diff --git a/src/main/resources/moonrise.mixins.json b/src/main/resources/moonrise.mixins.json index 3f370eab..da29746c 100644 --- a/src/main/resources/moonrise.mixins.json +++ b/src/main/resources/moonrise.mixins.json @@ -108,6 +108,7 @@ "starlight.world.ChunkSerializerMixin", "starlight.world.WorldGenRegionMixin", "util_thread_counts.UtilMixin", + "util_threading_detector.PalettedContainerMixin", "util_threading_detector.ThreadingDetectorMixin", "util_time_source.UtilMixin" ],