-
Notifications
You must be signed in to change notification settings - Fork 358
Description
Enhancement request:
What should be added/changed?
Re-introduce get_adjusted_points optimizations from #1524, which were lost in the hitbox refactor.
What would it help with?
performance of collision detection
#1641 undid some of the get_adjusted_points optimizations from #1524
These code snippets have a lot of extra dictionary lookups and function calls for constant values which are repeated multiple times for every single point.
Lines 115 to 121 in 51148f8
| def _adjust_point(point) -> Point: | |
| x, y = point | |
| x *= self.scale[0] | |
| y *= self.scale[1] | |
| return (x + self.position[0], y + self.position[1]) |
Lines 157 to 172 in 51148f8
| def _adjust_point(point) -> Point: | |
| x, y = point | |
| x *= self.scale[0] | |
| y *= self.scale[1] | |
| if rad: | |
| rot_x = x * rad_cos - y * rad_sin | |
| rot_y = x * rad_sin + y * rad_cos | |
| x = rot_x | |
| y = rot_y | |
| return ( | |
| x + self.position[0], | |
| y + self.position[1], | |
| ) |
For example, when computing adjusted points for an 8 point hitbox, these dictionary lookups and calls happen a lot:
self.position()called 16 timesself._positiondictionary lookup 16 timesself.scale()called 16 timesself._scaledictionary lookup 16 times_scale[0]8 times_scale[1]8 times_position[0]8 times_position[1]8 times
#1524 stored position and scale x and y values in local variables.
https://github.com/pythonarcade/arcade/pull/1524/files#diff-8c15b2f64db68ce7a9f80e835102bdcb0790386bbc2972bdc154a43abcd8a2df