-
-
Notifications
You must be signed in to change notification settings - Fork 158
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 all Rect/FRect
methods via pgRect_FromObject
#2908
Merged
itzpr3d4t0r
merged 3 commits into
pygame-community:main
from
itzpr3d4t0r:optimize_rect_conversion_function
Jul 10, 2024
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
How much of a performance effect does force-inlining have here?
I'm skeptical of this change because it's a large-ish function that's used in a lot of places. We should see if the performance improvement justifies the increase in size in this case
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.
Removing inlining gives this performance loss (5-30% generally about 10%), but I'd be more interested in knowing how much inlining would cost here in terms of code size. The function gets inlined only inside of rect_impl.h, outside this we use function pointers which inherently don't inline the function body.
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.
I got these results:
12759704 bytes
12773283 bytes
So inlining increases code size by 0.1 %, or a 1.00106X increase. I believe this is a fair increase for up to 30% performance improvement.
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.
After a long time banging my head into a wall and needing special support from Ankith, I have my own comparison.
It seems like on my computer the new buildconfig chooses mingw, and for some reason this PR doesn't change the size at all (not a single byte) when using mingw.
So now that I have the special flags to actually build pygame-ce with the correct compiler (
pip install . -Csetup-args="--vsenv"
), I can see the difference.This brings
rect.cp39-win_amd64.pyd
from 70,656 bytes to 108,544 bytes. This is an increase of 37,888 bytes, or 53%.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 so I've swapped
PG_FORCEINLINE
for a simplerinline
and checked code size. It stayed very close to 70kb so almost the same as before but the performance loss was mitigated a bit: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.
Infact I got these results (just for rect.pyd this time, python 3.12):