Skip to content

(F)Rect.inflate(_ip) FASTCALL #3518

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

ankith26
Copy link
Member

@ankith26 ankith26 commented Jun 30, 2025

A low hanging fruit for minor performance enhancements, and also makes the code inline with rest of the file.

Benchmarking results

Argument Before After Improvement (%)
Vector2 0.000643572 0.000483602 25.0%
list 0.000617076 0.000442811 28.2%
tuple 0.000617972 0.000454474 26.5%
2 args, inline 0.000611962 0.000431108 29.5%

Benchmarking code

from timeit import repeat
from pygame import Rect, Vector2

r = Rect(0, 0, 100, 100)
a1 = Vector2(10, 10)
a2 = [10, 10]
a3 = (10, 10)

G = globals()
N = 10000
R = 1000

tests = [
    ("Vector2", "r.inflate(a1)"),
    ("list", "r.inflate(a2)"),
    ("tuple", "r.inflate(a3)"),
    ("2 args, inline", "r.inflate(10, 10)"),
]

for name, test in tests:
    print(name + ": ", end="")
    print(min(repeat(test, globals=G, number=N, repeat=R)))

@ankith26 ankith26 requested a review from a team as a code owner June 30, 2025 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant