Skip to content

reduce GC by skipping empty handlers in recipe handling#4909

Open
GilbertzRivi wants to merge 2 commits into
GregTechCEu:1.20.1from
GilbertzRivi:recipe-optimization
Open

reduce GC by skipping empty handlers in recipe handling#4909
GilbertzRivi wants to merge 2 commits into
GregTechCEu:1.20.1from
GilbertzRivi:recipe-optimization

Conversation

@GilbertzRivi

Copy link
Copy Markdown

What

Reduce the amount of allocations in recipe handlers to improve performance

Implementation Details

It skips RecipeRunner and some lists allocations when the recipe handlers are empty, for example ranged inputs are almost always empty and they were allocating memory that had to be cleared by GC without any reason. The performance impact is visible mainly on pattern buffers.

AI Usage

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

Agent Used

ClaudeCode Sonet 4.6

Usage Description

I used it for digging into the repo to help me get a wider view on the problem and to analyze different interactions between buffers and recipe logic, that helped me to come up with that solution.

Outcome

Reduces lag spikes from pattern buffers, reduces GC usage and slightly improves TPS.

How Was This Tested

I made those changes in my addon with mixins, and tested on my monifactory instance on 7.5.3 with spark profiler
Before:
image
After:
image

The lag spikes are random and I was not able to catch one when profiling (mostly because Im using my custom buffers with different logic (Ill make another PR with that soon)) but I catched one when not profiling and spark said the max tick time was ~500ms when before those lag spikes were above 5000ms

Additional Information

this chart shows all the info i gathered during profiling on a test world with 8 RHFs, the "normal" is the standard pattern buffer, "expanded" is the expanded one from gtmutils, and "insane" are the buffers with my custom logic. The time in us is accumulated across 60sec.
image

@GilbertzRivi GilbertzRivi requested a review from a team as a code owner June 5, 2026 06:02
@github-actions github-actions Bot added the 1.20.1 label Jun 5, 2026
@DilithiumThoride DilithiumThoride added type: refactor Suggestion to refactor a section of code Release: Patch - 0.0.X Smaller changes that either are bug fixes or very minor tweaks. labels Jun 5, 2026
boolean isTick, boolean simulated) {
if (contents.isEmpty()) {
return ActionResult.PASS_NO_CONTENTS;
} ;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

potential typo with the random ; here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ill fix at monday

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.20.1 Release: Patch - 0.0.X Smaller changes that either are bug fixes or very minor tweaks. type: refactor Suggestion to refactor a section of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants