-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
Optimized pgRect_FromObject
#2465
Optimized pgRect_FromObject
#2465
Conversation
Modifying `RectExport_RectFromObject` to also check for the other type of rect and return an SDL_(F)Rect object earlier.
This comment was marked as outdated.
This comment was marked as outdated.
I think you should test this with something like colliderect to avoid any potential extra overheads and not fblits. Also using something like min(repeat(...)) or mean(repeat(...)) instead of just timeit is also advisable as it gives a better estimate since outliers in the timings won't count towards a single value but will be discarded. Also could we do it all in a single check that covers both cases? like a generic check? |
This comment was marked as outdated.
This comment was marked as outdated.
Slightly confused here; why isn't |
Because for |
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.
LGTM, thanks for the PR 🎉
We've had a lot of discussion about rounding recently, I'm concerned this explicit cast strategy closes the door on changing rounding behaviors in the future, or might lead to different rounding behavior based on exact object type. |
I don't think this change is changing any behaviour currently, even the generic/old path seems to truncate floats |
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.
This seems fine to me. I agree it doesn't appear to be changing current behaviour, or adding much more of it. We should probably address any float->int rounding strategy changes in a separate issue/PR.
Modifying
RectExport_RectFromObject
to also check for the other type of rect and return an SDL_(F)Rect object earlier.The speed difference was tested using
Surface.fblits
(fast iteration over sequence, thus many calls to this internal API) with small surfaces to minimize blit overhead:For some reason it appears that
Rect
usage times also improve (i.e., the speed improves), but nothing's really changed in that aspect, so mainly I was focusing onFRect
s and saw a 20%+ speed increase.EDIT: ran my version comparison test again and this time
Rect
s were down 14%, which shows rather high volatility, but realistically the speed should be about the same as it was before (so averages cancel out or something).FRect
s did show a steady improvement of 28% this time.EDIT2/UPDATE2: ran the test again,
Rect
s down 3%,FRect
s up 40%Btw, this is how I compare it across versions (both wheels built locally,
-main
version is just a wheel I built upon creating the branch, so that's basically currentmain
):