Compare commits

..
Author SHA1 Message Date
Martin Robertz 3fecc84f59 update
(cherry picked from commit d05a9eafb3)
2024-05-04 21:08:22 +02:00
Lasm Gratel cba4cb7856 Concurrent recipe profiler (#478)
* concurrent recipe profiler

* eliminate NPE by giving nulls a name

(cherry picked from commit 5056fe5437)
2024-05-04 21:08:17 +02:00
4 changed files with 6 additions and 24 deletions

No files matched your search

@@ -667,10 +667,6 @@ public class NEIClientConfig {
return !getBooleanSetting("tools.catalyst_load_from_config");
}
public static boolean isProfileRecipeEnabled() {
return NEIClientConfig.getBooleanSetting("inventory.profileRecipes");
}
public static void setEnabled(boolean flag) {
getSetting("inventory.widgetsenabled").setBooleanValue(flag);
}
@@ -39,7 +39,7 @@ public class ProfilerRecipeHandler implements ICraftingHandler, IUsageHandler {
@Override
public int numRecipes() {
if (!NEIClientConfig.isProfileRecipeEnabled()) return 0;
if (!NEIClientConfig.getBooleanSetting("inventory.profileRecipes")) return 0;
return (int) Math.ceil(
((crafting ? GuiCraftingRecipe.craftinghandlers.size() : GuiUsageRecipe.usagehandlers.size()) - 1)
@@ -35,15 +35,8 @@ class RecipeHandlerQuery<T extends IRecipeHandler> {
ArrayList<T> runWithProfiling(String profilerSection) {
TaskProfiler profiler = ProfilerRecipeHandler.getProfiler();
// Save the current config state here, as it may be altered
// if getRecipeHandlesParallel took so long and player accidentally changed config.
boolean profileRecipes = NEIClientConfig.isProfileRecipeEnabled();
if (profileRecipes) {
profiler.clear();
profiler.start(profilerSection);
}
profiler.clear();
profiler.start(profilerSection);
try {
ArrayList<T> handlers = getRecipeHandlersParallel();
@@ -56,7 +49,7 @@ class RecipeHandlerQuery<T extends IRecipeHandler> {
displayRecipeLookupError();
return new ArrayList<>(0);
} finally {
if (profileRecipes) profiler.end();
profiler.end();
}
}
@@ -14,21 +14,14 @@ public class AsyncTaskProfiler extends TaskProfiler {
public Map<String, Long> times = new ConcurrentHashMap<>();
@Override
public void start(String section) {
if (section == null) section = "<unnamed>";
threadedProfiler.get().start(section);
}
@Override
public void end() {
TaskProfiler profiler = threadedProfiler.get();
if (profiler != null) {
profiler.end();
if (profiler.times != null && !profiler.times.isEmpty()) {
times.putAll(threadedProfiler.get().times);
}
}
threadedProfiler.get().end();
times.putAll(threadedProfiler.get().times);
}
@Override