From 94271b866b50df7f212ec04ce2084b15df693be6 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Fri, 30 May 2025 21:35:52 -0400 Subject: [PATCH] Add world join profiling --- .../embeddedt/modernfix/ModernFixClient.java | 4 ++++ .../MinecraftMixin.java | 18 ++++++++++++++++++ .../WorldLoaderMixin.java | 18 ++++++++++++++++++ .../core/config/ModernFixEarlyConfig.java | 1 + 4 files changed, 41 insertions(+) create mode 100644 common/src/main/java/org/embeddedt/modernfix/common/mixin/feature/spark_profile_world_join/MinecraftMixin.java create mode 100644 common/src/main/java/org/embeddedt/modernfix/common/mixin/feature/spark_profile_world_join/WorldLoaderMixin.java diff --git a/common/src/main/java/org/embeddedt/modernfix/ModernFixClient.java b/common/src/main/java/org/embeddedt/modernfix/ModernFixClient.java index 320e2ab9..7dbee016 100644 --- a/common/src/main/java/org/embeddedt/modernfix/ModernFixClient.java +++ b/common/src/main/java/org/embeddedt/modernfix/ModernFixClient.java @@ -16,6 +16,7 @@ import org.embeddedt.modernfix.platform.ModernFixPlatformHooks; import org.embeddedt.modernfix.searchtree.JEIBackedSearchTree; import org.embeddedt.modernfix.searchtree.REIBackedSearchTree; import org.embeddedt.modernfix.searchtree.SearchTreeProviderRegistry; +import org.embeddedt.modernfix.spark.SparkLaunchProfiler; import org.embeddedt.modernfix.util.ClassInfoManager; import org.embeddedt.modernfix.world.IntegratedWatchdog; @@ -100,6 +101,9 @@ public class ModernFixClient { ModernFix.LOGGER.warn("Time from main menu to in-game was " + timeSpentLoading + " seconds"); ModernFix.LOGGER.warn("Total time to load game and open world was " + (timeSpentLoading + gameStartTimeSeconds) + " seconds"); } + if (ModernFixPlatformHooks.INSTANCE.modPresent("spark") && ModernFixMixinPlugin.instance.isOptionEnabled("feature.spark_profile_world_join.WorldJoin")) { + SparkLaunchProfiler.stop("world_join"); + } resetWorldLoadStateMachine(); } } diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/feature/spark_profile_world_join/MinecraftMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/feature/spark_profile_world_join/MinecraftMixin.java new file mode 100644 index 00000000..f817ec71 --- /dev/null +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/feature/spark_profile_world_join/MinecraftMixin.java @@ -0,0 +1,18 @@ +package org.embeddedt.modernfix.common.mixin.feature.spark_profile_world_join; + +import net.minecraft.client.Minecraft; +import org.embeddedt.modernfix.annotation.ClientOnlyMixin; +import org.embeddedt.modernfix.spark.SparkLaunchProfiler; +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; + +@Mixin(Minecraft.class) +@ClientOnlyMixin +public class MinecraftMixin { + @Inject(method = "prepareForMultiplayer", at = @At("HEAD")) + private void startProfiling(CallbackInfo ci) { + SparkLaunchProfiler.start("world_join"); + } +} diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/feature/spark_profile_world_join/WorldLoaderMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/feature/spark_profile_world_join/WorldLoaderMixin.java new file mode 100644 index 00000000..713886b7 --- /dev/null +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/feature/spark_profile_world_join/WorldLoaderMixin.java @@ -0,0 +1,18 @@ +package org.embeddedt.modernfix.common.mixin.feature.spark_profile_world_join; + +import net.minecraft.server.WorldLoader; +import org.embeddedt.modernfix.annotation.ClientOnlyMixin; +import org.embeddedt.modernfix.spark.SparkLaunchProfiler; +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.CallbackInfoReturnable; + +@Mixin(WorldLoader.class) +@ClientOnlyMixin +public class WorldLoaderMixin { + @Inject(method = "load", at = @At("HEAD")) + private static void startProfiling(CallbackInfoReturnable cir) { + SparkLaunchProfiler.start("world_join"); + } +} diff --git a/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java b/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java index b488e4c0..3f40fbfd 100644 --- a/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java +++ b/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java @@ -182,6 +182,7 @@ public class ModernFixEarlyConfig { .put("mixin.feature.snapshot_easter_egg", true) .put("mixin.feature.warn_missing_perf_mods", true) .put("mixin.feature.spark_profile_launch", false) + .put("mixin.feature.spark_profile_world_join", false) .put("mixin.feature.log_stdout_in_log_files", true) .put("mixin.devenv", isDevEnv) .put("mixin.perf.remove_spawn_chunks", isDevEnv)