reduce GC by skipping empty handlers in recipe handling#4909
Open
GilbertzRivi wants to merge 2 commits into
Open
reduce GC by skipping empty handlers in recipe handling#4909GilbertzRivi wants to merge 2 commits into
GilbertzRivi wants to merge 2 commits into
Conversation
1 task
htmlcsjs
reviewed
Jun 5, 2026
| boolean isTick, boolean simulated) { | ||
| if (contents.isEmpty()) { | ||
| return ActionResult.PASS_NO_CONTENTS; | ||
| } ; |
Member
There was a problem hiding this comment.
potential typo with the random ; here?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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:
After:
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.
