-
-
Notifications
You must be signed in to change notification settings - Fork 160
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
Rewrite sprite collision functions #3209
base: main
Are you sure you want to change the base?
Conversation
I heard somewhere (can't find a back reference) that the old "pull out a bound function into a local variable" trick is actually slower in the most recent versions of Python, I'd be interested to see you look into it with this case. EDIT: Found it-- https://youtu.be/z0-4EwIFeJo?si=sTOUIHgumGYGiyZl&t=1112 |
Thanks. I looked into it and found no noticeable performance increase nor penalty from either using Since I saw no performance increase from removing the cached methods/functions, I will leave it in just in case python 3.9 or 3.10 needs it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, LGTM 👍
Nice simplification. I renamed the 'crashed' variable because it's name didn't make much sense and this was a good opportunity.
The current sprite collision functions code has some code repetition. This implementation structures it differently, which has a few effects.
dokill
is true inspritecollide
orgroupcollide
, the sprites are killed after all colliding sprites have been determined, instead of during iteration (should be unnoticeable)group.sprites()
is replaced by iteration overgroup
itself, resulting in the following:dokill
is False)dokill
is False)ignore_self
parameter, e.g., with the new structurePerformance tested in 3.13.0, no regression (similar performance).
Renamed a few local variables for clarity.