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

Improve moveToTarget performance by reusing the diff vector #2427

Closed
Hwan-seok opened this issue Mar 24, 2023 · 0 comments · Fixed by #2429
Closed

Improve moveToTarget performance by reusing the diff vector #2427

Hwan-seok opened this issue Mar 24, 2023 · 0 comments · Fixed by #2429
Assignees

Comments

@Hwan-seok
Copy link
Contributor

What could be improved

Add optional reusable diff argument which is Vector2 to the Vector2.moveToTarget.

void moveToTarget(
Vector2 target,
double ds,
) {
if (this != target) {
final diff = target - this;
if (diff.length < ds) {
setFrom(target);
} else {
diff.scaleTo(ds);
setFrom(this + diff);
}
}
}

Why should this be improved

At present, if there is a continuous call of the moveToTarget() inside for example update(), it could impact the performance since it has a clone().
Adding a reusable vector can prevent creating a new Vector2 object in every tick.

Any risks?

No

More information

Are you interested in working on a PR for this? Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant