Optimize MultiPart and ParallelHatch performance #2684
Merged
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
This PR aims to optimize some parts of the Multiblock Lifecycle.
IMultiPart
needed to query the controllers it was attached to, it would iterate through all of its known controller positions and return a new List every time.Implementation Details
IMultiController
to be moved from its current position without triggering a structure update and thus removing itself from the controller set, we can also keep track of a Set ofIMultiControllers
. I have used aReferenceLinkedOpenHashSet
from FastUtil, as we only really care about references and using a LinkedSet provides us with consistent iterations, as well as quick access to the first controller in the set.This Set does need to be populated manually on the client-side due to an inability to sync, so that is the reason why maintaining the
controllerPositions
set is useful.MultiblockControllerMachine
class as a simple field. I have chosen to make the method return anOptional
to better fit in with our current usages, but it can be switched to aNullable
if desired.Additionally, some small tweaks have been added:
!getControllers.isEmpty()
calls have been changed toisFormed()
onUnload
has been cleaned up a bit.Outcome
Performance.
600s runs in fairly stressful situations
Shown is average MSPT spent executing the method
MultiPart example in
RotorHolderPartMachine
Parallel Hatch searching example in
GTRecipeModifiers#hatchParallel
(ignore the
Optional.map
, it's the other bits that are relevant)