From b04445138664ac1e8151286b0c3858c442da9419 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 23 Apr 2022 15:48:39 +0800 Subject: Compare versions more on a smaller scale --- .../me/shedaniel/rei/RoughlyEnoughItemsInitializer.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java index 5b56c0739..adc82c4c4 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java @@ -30,14 +30,16 @@ import java.lang.invoke.MethodHandles; import java.lang.reflect.Method; public class RoughlyEnoughItemsInitializer { - public static final String COMPATIBLE_MC_VERSION = "1.18"; + public static final String COMPATIBLE_MC_VERSION_LOW = "1.18.2"; + public static final String COMPATIBLE_MC_VERSION_HIGH = "1.19"; public static void onInitialize() { RoughlyEnoughItemsState.env = isClient() ? EnvType.CLIENT : EnvType.SERVER; RoughlyEnoughItemsState.isDev = isDev(); - - if (getMinecraftVersion().startsWith("1.") && !getMinecraftVersion().startsWith(COMPATIBLE_MC_VERSION)) { - RoughlyEnoughItemsState.error("Your current REI version (for " + COMPATIBLE_MC_VERSION + ") is not compatible with your current Minecraft version (" + getMinecraftVersion() + ")."); + + String minecraftVersion = getMinecraftVersion(); + if (minecraftVersion.startsWith("1.") && (compareVersions(minecraftVersion, COMPATIBLE_MC_VERSION_LOW) < 0 || compareVersions(minecraftVersion, COMPATIBLE_MC_VERSION_HIGH) >= 0)) { + RoughlyEnoughItemsState.error("Your current REI version (for >=" + COMPATIBLE_MC_VERSION_LOW + " and <" + COMPATIBLE_MC_VERSION_HIGH + ") is not compatible with your current Minecraft version (" + minecraftVersion + ")."); } checkMods(); @@ -106,4 +108,9 @@ public class RoughlyEnoughItemsInitializer { public static String getMinecraftVersion() { throw new AssertionError(); } + + @ExpectPlatform + public static int compareVersions(String version1, String version2) { + throw new AssertionError(); + } } \ No newline at end of file -- cgit From f024acf13e0f75d5872ec20539870bd83179458e Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 23 Apr 2022 22:37:42 +0800 Subject: Show total load time in performance screen --- .../client/gui/performance/PerformanceScreen.java | 3 + .../rei/impl/common/plugins/PluginManagerImpl.java | 95 ++++++++++++++-------- 2 files changed, 66 insertions(+), 32 deletions(-) (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java index b0a77fae4..356c7c5b0 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java @@ -145,6 +145,7 @@ public class PerformanceScreen extends Screen { })); } list = new PerformanceEntryListWidget(); + long[] totalTime = {0}; RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.getStages().forEach((stage, inner) -> { List entries = new ArrayList<>(); inner.times().forEach((obj, time) -> { @@ -158,9 +159,11 @@ public class PerformanceScreen extends Screen { if ((inner.totalNano() - separateTime) > 1000000) { entries.add(new EntryListEntry(new TextComponent("Miscellaneous Operations"), inner.totalNano() - separateTime)); } + totalTime[0] += inner.totalNano(); entries.sort(Comparator.comparingLong(value -> value.time).reversed()); list.addItem(new SubCategoryListEntry(new TextComponent(stage), (List) (List) entries, inner.totalNano(), false)); }); + list.children().add(0, new EntryListEntry(new TextComponent("Total Load Time"), totalTime[0])); addWidget(list); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java index 249ba8a2c..3fa5f150d 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java @@ -40,7 +40,6 @@ import me.shedaniel.rei.api.common.registry.ReloadStage; import me.shedaniel.rei.api.common.registry.Reloadable; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.impl.common.logging.performance.PerformanceLogger; -import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.server.MinecraftServer; import org.apache.commons.lang3.tuple.MutablePair; @@ -50,7 +49,8 @@ import org.jetbrains.annotations.Nullable; import java.io.Closeable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Consumer; +import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; import java.util.function.LongConsumer; import java.util.function.UnaryOperator; @@ -63,6 +63,9 @@ public class PluginManagerImpl

> implements PluginManager< private boolean reloading = false; private final List> plugins = new ArrayList<>(); private final LongConsumer reloadDoneListener; + private final Stopwatch reloadStopwatch = Stopwatch.createUnstarted(); + private boolean forcedMainThread; + private final Stopwatch forceMainThreadStopwatch = Stopwatch.createUnstarted(); @SafeVarargs public PluginManagerImpl(Class

pluginClass, UnaryOperator> view, LongConsumer reloadDoneListener, Reloadable... reloadables) { @@ -173,19 +176,32 @@ public class PluginManagerImpl

> implements PluginManager< return new SectionClosable(stage, section); } - private void pluginSection(ReloadStage stage, String sectionName, List> list, @Nullable Reloadable reloadable, Consumer> consumer) { + @FunctionalInterface + private interface SectionPluginSink { + void accept(boolean respectMainThread, Runnable task); + } + + private void pluginSection(ReloadStage stage, String sectionName, List> list, @Nullable Reloadable reloadable, BiConsumer, SectionPluginSink> consumer) { for (PluginWrapper

wrapper : list) { try (SectionClosable section = section(stage, sectionName + wrapper.getPluginProviderName() + "/")) { - if (reloadable == null || !wrapper.plugin.shouldBeForcefullyDoneOnMainThread(reloadable)) { - consumer.accept(wrapper); - } else { - RoughlyEnoughItemsCore.LOGGER.warn("Forcing plugin " + wrapper.getPluginProviderName() + " to run on the main thread for " + sectionName + "! This is extremely dangerous, and have large performance implications."); - if (Platform.getEnvironment() == Env.CLIENT) { - EnvExecutor.runInEnv(Env.CLIENT, () -> () -> queueExecutionClient(() -> consumer.accept(wrapper))); + consumer.accept(wrapper, (respectMainThread, runnable) -> { + if (!respectMainThread || reloadable == null || !wrapper.plugin.shouldBeForcefullyDoneOnMainThread(reloadable)) { + runnable.run(); } else { - queueExecution(() -> consumer.accept(wrapper)); + try { + forcedMainThread = true; + forceMainThreadStopwatch.start(); + RoughlyEnoughItemsCore.LOGGER.warn("Forcing plugin " + wrapper.getPluginProviderName() + " to run on the main thread for " + sectionName + "! This is extremely dangerous, and have large performance implications."); + if (Platform.getEnvironment() == Env.CLIENT) { + EnvExecutor.runInEnv(Env.CLIENT, () -> () -> queueExecutionClient(runnable)); + } else { + queueExecution(runnable); + } + } finally { + forceMainThreadStopwatch.stop(); + } } - } + }); } catch (Throwable throwable) { RoughlyEnoughItemsCore.LOGGER.error(wrapper.getPluginProviderName() + " plugin failed to " + sectionName + "!", throwable); } @@ -205,36 +221,50 @@ public class PluginManagerImpl

> implements PluginManager< @Override public void pre(ReloadStage stage) { + this.forcedMainThread = false; + this.forceMainThreadStopwatch.reset(); + this.reloadStopwatch.reset().start(); List> plugins = new ArrayList<>(getPluginWrapped().toList()); plugins.sort(Comparator.comparingDouble(PluginWrapper

::getPriority).reversed()); Collections.reverse(plugins); try (SectionClosable preRegister = section(stage, "pre-register/"); PerformanceLogger.Plugin perfLogger = RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.stage("Pre Registration")) { - pluginSection(stage, "pre-register/", plugins, null, plugin -> { + pluginSection(stage, "pre-register/", plugins, null, (plugin, sink) -> { try (PerformanceLogger.Plugin.Inner inner = perfLogger.plugin(new Pair<>(plugin.provider, plugin.plugin))) { - ((REIPlugin

) plugin.plugin).preStage(this, stage); + sink.accept(false, () -> { + ((REIPlugin

) plugin.plugin).preStage(this, stage); + }); } }); } catch (Throwable throwable) { new RuntimeException("Failed to run pre registration").printStackTrace(); } + this.reloadStopwatch.stop(); } @Override public void post(ReloadStage stage) { + this.reloadStopwatch.start(); List> plugins = new ArrayList<>(getPluginWrapped().toList()); plugins.sort(Comparator.comparingDouble(PluginWrapper

::getPriority).reversed()); Collections.reverse(plugins); try (SectionClosable postRegister = section(stage, "post-register/"); PerformanceLogger.Plugin perfLogger = RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.stage("Post Registration")) { - pluginSection(stage, "post-register/", plugins, null, plugin -> { + pluginSection(stage, "post-register/", plugins, null, (plugin, sink) -> { try (PerformanceLogger.Plugin.Inner inner = perfLogger.plugin(new Pair<>(plugin.provider, plugin.plugin))) { - ((REIPlugin

) plugin.plugin).postStage(this, stage); + sink.accept(false, () -> { + ((REIPlugin

) plugin.plugin).postStage(this, stage); + }); } }); } catch (Throwable throwable) { new RuntimeException("Failed to run post registration").printStackTrace(); } + this.reloadStopwatch.stop(); + reloadDoneListener.accept(this.reloadStopwatch.elapsed(TimeUnit.MILLISECONDS)); + if (forcedMainThread) { + RoughlyEnoughItemsCore.LOGGER.warn("Forcing plugins to run on main thread took " + forceMainThreadStopwatch); + } } private static String name(Class clazz) { @@ -246,8 +276,8 @@ public class PluginManagerImpl

> implements PluginManager< @Override public void startReload(ReloadStage stage) { try { + this.reloadStopwatch.start(); reloading = true; - long startTime = Util.getMillis(); // Pre Reload try (SectionClosable startReloadAll = section(stage, "start-reload/"); @@ -284,27 +314,29 @@ public class PluginManagerImpl

> implements PluginManager< } } - pluginSection(stage, "reloadable-plugin/" + name(reloadableClass) + "/", plugins, reloadable, plugin -> { + pluginSection(stage, "reloadable-plugin/" + name(reloadableClass) + "/", plugins, reloadable, (plugin, sink) -> { try (PerformanceLogger.Plugin.Inner inner = perfLogger.plugin(new Pair<>(plugin.provider, plugin.plugin))) { - for (Reloadable

listener : reloadables) { - try { - listener.beforeReloadablePlugin(stage, reloadable, plugin.plugin); - } catch (Throwable throwable) { - throwable.printStackTrace(); - } - } - - try { - reloadable.acceptPlugin(plugin.plugin, stage); - } finally { + sink.accept(true, () -> { for (Reloadable

listener : reloadables) { try { - listener.afterReloadablePlugin(stage, reloadable, plugin.plugin); + listener.beforeReloadablePlugin(stage, reloadable, plugin.plugin); } catch (Throwable throwable) { throwable.printStackTrace(); } } - } + + try { + reloadable.acceptPlugin(plugin.plugin, stage); + } finally { + for (Reloadable

listener : reloadables) { + try { + listener.afterReloadablePlugin(stage, reloadable, plugin.plugin); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + } + } + }); } }); @@ -334,8 +366,7 @@ public class PluginManagerImpl

> implements PluginManager< } } - long usedTime = Util.getMillis() - startTime; - reloadDoneListener.accept(usedTime); + this.reloadStopwatch.stop(); } catch (Throwable throwable) { throwable.printStackTrace(); } finally { -- cgit From ad973eb6c024644711f4febb851fea7a67bc2db5 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 24 Apr 2022 01:13:57 +0800 Subject: Fix performance screen time --- .../shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java index 356c7c5b0..7e1b11719 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java @@ -159,9 +159,9 @@ public class PerformanceScreen extends Screen { if ((inner.totalNano() - separateTime) > 1000000) { entries.add(new EntryListEntry(new TextComponent("Miscellaneous Operations"), inner.totalNano() - separateTime)); } - totalTime[0] += inner.totalNano(); + totalTime[0] += Math.max(inner.totalNano(), separateTime); entries.sort(Comparator.comparingLong(value -> value.time).reversed()); - list.addItem(new SubCategoryListEntry(new TextComponent(stage), (List) (List) entries, inner.totalNano(), false)); + list.addItem(new SubCategoryListEntry(new TextComponent(stage), (List) (List) entries, Math.max(inner.totalNano(), separateTime), false)); }); list.children().add(0, new EntryListEntry(new TextComponent("Total Load Time"), totalTime[0])); addWidget(list); -- cgit