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

Cleanup recalcTrack #535

Merged
merged 1 commit into from Apr 20, 2023
Merged

Conversation

quaelnix
Copy link
Collaborator

@quaelnix quaelnix commented Apr 18, 2023

The new code is functionally equivalent.

@quaelnix quaelnix temporarily deployed to BRouter April 18, 2023 13:31 — with GitHub Actions Inactive
@afischerdev
Copy link
Collaborator

@quaelnix
Thanks for the cleaning idea.

But I'm not sure if I agree with it. Beautifying readability is only one part.
The variable integers are allocated, filled, used and freed in each iteration of the loop.
So I prefer to allocate the variables before loop. This may be old school.
I'm not sure if the modern compilers adjust this out.

@quaelnix
Copy link
Collaborator Author

I'm not sure if the modern compilers adjust this out.

Even if they would not optimize stuff like this (which they do) the performance difference would be small enough that it does not justify a 3x increase in lines of code, which makes it a lot harder to understand what is going on than necessary.

Beautifying readability is only one part.

This cleanup was a byproduct from back in the time when I was double checking what this function actually does. Feel free to close the pull request if you dislike the changes.

@quaelnix
Copy link
Collaborator Author

@afischerdev
Copy link
Collaborator

@quaelnix
Thanks for the link.

I didn't mean the for (int i = 0; ...) variant.
So I did a small java test and compiled it to byte code (javap -c).

Routine with variable declaration inside the loop is two instructions shorter.
Interesting thing.

TestLoop.java.txt
TestLoop.byte.txt

@quaelnix
Copy link
Collaborator Author

Keeping the scope of the variables small also makes the life of the optimizer easier.

@afischerdev
Copy link
Collaborator

It works for generic variables. But I'm still not sure about Java classes. The overhead of allocating and deallocating within a loop can vary by class.
E.g. OnDraw complains regularly when I declare new classes within.

@afischerdev afischerdev merged commit 4529a40 into abrensch:master Apr 20, 2023
1 check passed
@quaelnix quaelnix deleted the recalc-track-cleanup branch April 20, 2023 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants