-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Mechanical arm optimizations #8613
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
base: mc1.20.1/dev
Are you sure you want to change the base?
Mechanical arm optimizations #8613
Conversation
-Lazy updating during SEARCH_INPUTS phase so as to not make the arm search for targets on every tick. This should help with performance with many arms or arms that have lots of targets -Replaced if-else-if blocks that checked the arm's Phase with Switch statements -Cached getSlotCount result for arm interaction point slot iterations, should help when iterating high slot counts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is targeted as an optimization could you share some before and after profiles to prove it's faster, or at least a graph of mspt over time proving that load is actually spread across ticks better?
@@ -54,10 +54,16 @@ | |||
|
|||
public class ArmBlockEntity extends KineticBlockEntity implements TransformableBlockEntity { | |||
|
|||
// Server Statics | |||
private static final int SearchInputsRate = 20; // the rate at which the arm will search for targets while in SEARCH_INPUTS phase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static final int SearchInputsRate = 20; // the rate at which the arm will search for targets while in SEARCH_INPUTS phase | |
private static final int SEARCH_INPUTS_RATE= 20; // the rate at which the arm will search for targets while in SEARCH_INPUTS phase |
same for the other static field
case DANCING: | ||
boolean forcedSearch = forceSearchInputsTicks > 0; | ||
if (forcedSearch || (level.getGameTime() + randomSearchTickOffset) % SearchInputsRate == 0) { | ||
if(forcedSearch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(forcedSearch) { | |
if (forcedSearch) { |
case SEARCH_INPUTS: | ||
case DANCING: | ||
boolean forcedSearch = forceSearchInputsTicks > 0; | ||
if (forcedSearch || (level.getGameTime() + randomSearchTickOffset) % SearchInputsRate == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably make it clear in the comments above that the offset will be modulo'd and explain why
-Lazy updating during SEARCH_INPUTS phase so as to not make the arm search for targets on every tick. This should help with performance with many arms or arms that have lots of targets. I set the update rate to every 20 ticks (so 1 second), a too high of a number might make the arms feel unresponsive. I decided to add a short period after the arm inserts an item to search for targets on every tick, so the arm will try to act right after it inserted an item
-Replaced if-else-if blocks that checked the arm's Phase with Switch statements
-Cached getSlotCount result for arm interaction point slot iterations, should help when iterating high slot counts
-Added comments to explain what i was trying to achieve/how the changes work