Skip to content

Rhl cache - #5165

Open
GilbertzRivi wants to merge 4 commits into
GregTechCEu:1.20.1from
GilbertzRivi:rhl-cache
Open

Rhl cache#5165
GilbertzRivi wants to merge 4 commits into
GregTechCEu:1.20.1from
GilbertzRivi:rhl-cache

Conversation

@GilbertzRivi

Copy link
Copy Markdown
Contributor

What

Adding cache to recipe handler so it can skip searching for recipes when nothing in the inputs/outputs changed

Implementation Details

I added RecipeCapabilityVersions, one instance per IRecipeCapabilityHolder, holding three counters and a cached group map, inputVersion and outputVersion that are bumped on handler content changes and topologyVersion that is bumped when the handler set changes for example when you add a bus or paint it.

AI Usage

  • Yes AI driven tools were used for this pull request.

Agent Used

ClaudeCode Opus 4.8

Agent Usage Description

I used it for basic sanity checking my work if i didn't miss anything important, and to help me get a wider view of the repo and the thing i wanted to do. I also used it to make a tool to measure the performance but it was not commited to the repo as it was only a tool.

Outcome

It increases performance in bases with hundreds of machines and on weaker hardware.
image

How Was This Tested

My friend tested this on 7.5.3 then I moved all changes to this branch and on weaker CPU in endgame monifactory base the change was impressive
image
it says 10.09 sec saved in 10s window because it was assuming the game runs at stable 20tps and it actually ran at ~7tps so it was not 10s but ~30s window, still about 1/3 time saved. Its also an estimation, it was comparing cache hit time vs full search, but the amount of measurements is high so I guess its rather accurate.

Additional Information

I also tried to optimize handle recipe itself but its so fast that cache hit was slower than the real recipe handling on average.
image
All I did with that is calling it less frequent when the machine is idle and the conditions are the same, and the machine reports no errors.

Additional Information 2

i changed

    @Override
    public double getTotalContentAmount() {
        return energyStored;        // from this
        return getEnergyStored();   // to that
    }

so energy containers that override the getter report their real stored energy and are no longer skipped as empty by the prefilter.

Additional Information 3

My friend profiled this change and a change to stocking input buses (I'll pr it next) with spark and the results are bellow (screenshots + links because links expire):
image
image
OLD: https://spark.lucko.me/MjRH6gc91y
NEW: https://spark.lucko.me/JmBrjCa5tZ
I also profiled this a bit earlier when not all the current changes were implemented and I did it on a weaker laptop, results bellow:
image
image
OLD: https://spark.lucko.me/MfsQrUmAzH
NEW: https://spark.lucko.me/XWbaUwQIkc

@GilbertzRivi
GilbertzRivi requested a review from a team as a code owner July 21, 2026 22:50

@jurrejelle jurrejelle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only nits I have, I do want reviews by some others as well

Comment thread src/main/java/com/gregtechceu/gtceu/api/recipe/RecipeRunner.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/recipe/RecipeRunner.java Outdated
@GilbertzRivi GilbertzRivi mentioned this pull request Jul 22, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants