-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Many hasRecipe calls, no cache #123
Comments
My initial thought would be an LRU cache for recipes, set to maybe |
Just wanted to note that I am having a chance to sit down and look at the code and I already see LRU recipe caches! So there may be more to the problem than I first thought. I am learning more! |
Alright, I worked my way through and found a config option:
to use in I'm curious whether you think it might be worth tuning defaults? Or even, implementing a dynamic LRU cache by measuring the amount of recipe requests per |
Okay, still digging (do you have a Discord? :)) It seems like |
I think this is the real fix: diff --git a/src/main/java/ironfurnaces/tileentity/furnaces/BlockIronFurnaceTileBase.java b/src/main/java/ironfurnaces/tileentity/furnaces/BlockIronFurnaceTileBase.java
index a16b4ee..2a908ea 100644
--- a/src/main/java/ironfurnaces/tileentity/furnaces/BlockIronFurnaceTileBase.java
+++ b/src/main/java/ironfurnaces/tileentity/furnaces/BlockIronFurnaceTileBase.java
@@ -892,7 +892,7 @@ public abstract class BlockIronFurnaceTileBase extends TileEntityInventory imple
if (e.isBurning() || !itemstack.isEmpty() && !e.getItem(INPUT).isEmpty()) {
Optional<AbstractCookingRecipe> irecipe = Optional.empty();
if (!e.getItem(INPUT).isEmpty()) {
- irecipe = e.getRecipe(e.getItem(INPUT));
+ irecipe = e.getCache().computeIfAbsent(e.getItem(INPUT).getItem(), (item) -> e.getRecipe(new ItemStack(item)));
}
boolean valid = e.canSmelt(irecipe.orElse(null)); Unfortunately |
I was able to work through the problems and I was able to stress test. Before the change the furnace tick time was 28ms. With this change the tick time is ~0.2ms once the cache size is tuned. |
Forge Version
40.1.74
Fabric Version
No response
Iron Furnaces Version
1.18.2-3.3.1
Describe your issue
Performance is absolutely terrible.
As you can see, it's all about the recipe lookups:
I tried installing https://www.curseforge.com/minecraft/mc-mods/fastfurnace hoping that its recipe caching would apply to this mod. It doesn't.
This is critical for multiplayer servers. The profile I'm showing is one user's one single furnace on a 2-day-old server. That's absurd.
Crash Report
No response
The text was updated successfully, but these errors were encountered: