Skip to content
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 tuple creation for Rect getters #3072

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

itzpr3d4t0r
Copy link
Member

@itzpr3d4t0r itzpr3d4t0r commented Aug 20, 2024

I remember implementing this in old upstream pygame, but with the addition of FRect it got reverted to the old strategy with Py_BuildValue. It's still a micro optimization, but takes 0 effort on our part.

@itzpr3d4t0r itzpr3d4t0r added Performance Related to the speed or resource usage of the project rect pygame.rect labels Aug 20, 2024
@itzpr3d4t0r itzpr3d4t0r requested a review from a team as a code owner August 20, 2024 17:08
@itzpr3d4t0r itzpr3d4t0r changed the title optimized tuple creation for Rect getters Optimized tuple creation for Rect getters Aug 20, 2024
Copy link
Member

@damusss damusss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks :)

Copy link
Member

@Starbuck5 Starbuck5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, code changes look straightforward enough.

Copy link
Member

@ankith26 ankith26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks 🎈

@ankith26 ankith26 added this to the 2.5.2 milestone Aug 21, 2024
@ankith26 ankith26 merged commit dbdcd90 into pygame-community:main Aug 21, 2024
26 checks passed
@itzpr3d4t0r itzpr3d4t0r deleted the optimize-rect-getters branch August 22, 2024 08:56
@Starbuck5
Copy link
Member

Benchmark:

import pygame
import time

a = pygame.Rect(1,2,3,4)

start = time.time()
for _ in range(10000000):
    b = a.topleft
print(time.time() - start)

# main: 0.81-0.87 seconds
# 2.5.1 0.97-1.01 seconds

I'm calling it a 15% improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance Related to the speed or resource usage of the project rect pygame.rect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants