Skip to content
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

Optimize ParallelLogic loops slightly #2668

Open
wants to merge 1 commit into
base: 1.20.1
Choose a base branch
from

Conversation

jtuc
Copy link
Contributor

@jtuc jtuc commented Dec 29, 2024

What

Small optimizations to ParallelLogic.limitByInput/ParallelLogic.limitByOutputMerging

Implementation Details

These changes provide only a small speedup, but the methods are called so often that it was a noticable difference in my testing.
For limitByInput, just tracking the minimum instead of creating a set is an easy way to reduce allocations.
For limitByOutput, we do a similar tweak, but also refactor the loops slightly to avoid double-calling canVoid for each capability. (If canVoid is true for all capabilities, we still return parallelLimit and still avoid calling cap.limitParallel.)

Outcome

Ticks run a tiny bit faster. (It's not a huge difference, so wasn't totally sure it was worth making this PR, but since the code is now also a bit simpler it's probably worth doing.)

Additional Information

I'm not really sure what the intent of RecipeCapability#doMatchInRecipe is - I don't think the logic has changed, but since all the built-in recipes return true I couldn't test this.
I did also look at optimizing the ItemRecipeCapability methods, but I couldn't quite figure out the distinct handling, and the tweaks I did try weren't clear wins in spark.

@jtuc jtuc requested a review from a team as a code owner December 29, 2024 11:28
@screret screret added the type: refactor Suggestion to refactor a section of code label Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: refactor Suggestion to refactor a section of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants