Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
LasmGratel authored May 27, 2024
1 parent d05a9ea commit dc4426d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/main/java/codechicken/nei/NEIClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,10 @@ public static boolean loadCatalystsFromJar() {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public String getRecipeName() {

@Override
public int numRecipes() {
if (!NEIClientConfig.getBooleanSetting("inventory.profileRecipes")) return 0;
if (!NEIClientConfig.isProfileRecipeEnabled()) return 0;

return (int) Math.ceil(
((crafting ? GuiCraftingRecipe.craftinghandlers.size() : GuiUsageRecipe.usagehandlers.size()) - 1)
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/codechicken/nei/recipe/RecipeHandlerQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ class RecipeHandlerQuery<T extends IRecipeHandler> {

ArrayList<T> runWithProfiling(String profilerSection) {
TaskProfiler profiler = ProfilerRecipeHandler.getProfiler();
profiler.clear();
profiler.start(profilerSection);

// 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);
}

try {
ArrayList<T> handlers = getRecipeHandlersParallel();

Expand All @@ -49,7 +56,7 @@ ArrayList<T> runWithProfiling(String profilerSection) {
displayRecipeLookupError();
return new ArrayList<>(0);
} finally {
profiler.end();
if (profileRecipes) profiler.end();
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/main/java/codechicken/nei/util/AsyncTaskProfiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@ 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() {
threadedProfiler.get().end();
times.putAll(threadedProfiler.get().times);
TaskProfiler profiler = threadedProfiler.get();
if (profiler != null) {
profiler.end();
if (profiler.times != null && !profiler.times.isEmpty()) {
times.putAll(threadedProfiler.get().times);
}
}
}

@Override
Expand Down

0 comments on commit dc4426d

Please sign in to comment.