Skip to content

Clean _check_for_collision #1702

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

Merged
merged 3 commits into from
Apr 21, 2023

Conversation

gran4
Copy link
Contributor

@gran4 gran4 commented Apr 15, 2023

Fixed unpythonic code and made clearer variable names(some are up for debate).

@einarf
Copy link
Member

einarf commented Apr 15, 2023

This will affect the performance profile of the function. It was optimized to extract the the positions and size into new varaibles. @cspotcode should know more about this.

It's another example that we should have brifely discussed this first 😄

@cspotcode
Copy link
Collaborator

cspotcode commented Apr 15, 2023

Yeah, I benchmarked the code before and after, and this code made it about 20% faster. Attribute lookups and subscripting in python are relatively slow, and this code runs a huge number of times per frame. I should have added code comments to explain why we are intentionally using un-pythonic code.

I used the benchmarking script in /benchmarks/bench.sh to run the collision stress-test in /benchmarks/collisions/bench.py. I shared benchmarking results in #1524.

However, your improved variable names, like radius_sum_sq, look good to me.

@gran4
Copy link
Contributor Author

gran4 commented Apr 15, 2023

So if I decrease the attributes look ups it should be fine.

We should explain why it is unpythonic. Reverted that part
@cspotcode
Copy link
Collaborator

cspotcode commented Apr 15, 2023 via email

@Cleptomania Cleptomania merged commit 26cdee3 into pythonarcade:development Apr 21, 2023
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.

6 participants