-
Notifications
You must be signed in to change notification settings - Fork 343
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
Clean _check_for_collision #1702
Conversation
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 😄 |
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 |
So if I decrease the attributes look ups it should be fine. |
We should explain why it is unpythonic. Reverted that part
I forget, but I do remember doing my benchmarking on 3.11. We could bench
again and find out. `min()` is better than `math.min()` because the
latter has an extra dictionary lookup.
…On Sat, Apr 15, 2023, 4:27 PM Paul ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In arcade/sprite_list/collision.py
<#1702 (comment)>:
> (sprite1_width if sprite1_width > sprite1_height else sprite1_height)
+ (sprite2_width if sprite2_width > sprite2_height else sprite2_height)
@cspotcode <https://github.com/cspotcode> what's the overhead of this vs
max on recent Python versions?
—
Reply to this email directly, view it on GitHub
<#1702 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35OAVJCMP3FH73RNZ5ZLXBMADHANCNFSM6AAAAAAW7CVA74>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Fixed unpythonic code and made clearer variable names(some are up for debate).