Optimize ParallelLogic loops slightly #2668
Open
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
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. (IfcanVoid
is true for all capabilities, we still returnparallelLimit
and still avoid callingcap.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 returntrue
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.