Skip to content

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

Open
wants to merge 3 commits into
base: mc1.20.1/dev
Choose a base branch
from

Conversation

KptKosmit91
Copy link

@KptKosmit91 KptKosmit91 commented Jun 4, 2025

-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

-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
@KptKosmit91 KptKosmit91 marked this pull request as ready for review June 4, 2025 17:26
@VoidLeech VoidLeech added the pr type: feature PR adds a new feature or changes an existing feature label Jun 4, 2025
@KptKosmit91 KptKosmit91 changed the title Mech arm optimizations Mechanical arm optimizations Jun 5, 2025
Copy link
Contributor

@Jozufozu Jozufozu left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(forcedSearch) {
if (forcedSearch) {

case SEARCH_INPUTS:
case DANCING:
boolean forcedSearch = forceSearchInputsTicks > 0;
if (forcedSearch || (level.getGameTime() + randomSearchTickOffset) % SearchInputsRate == 0) {
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr type: feature PR adds a new feature or changes an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants