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

Remove use of Py_BuildValue("(ii)") #2819

Merged
merged 3 commits into from
Apr 26, 2024

Conversation

itzpr3d4t0r
Copy link
Member

This PR removes all occurrences of Py_BuildValue("(ii)") and swaps them with the faster pg_tuple_couple_from_values_int.

@itzpr3d4t0r itzpr3d4t0r added the Performance Related to the speed or resource usage of the project label Apr 24, 2024
@itzpr3d4t0r itzpr3d4t0r requested a review from a team as a code owner April 24, 2024 15:24
@damusss
Copy link
Member

damusss commented Apr 24, 2024

I don't know if my recent PR will be approved but I'm also gonna replace that function, thanks for the "idea"

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.

I did some benchmarking of Surface.get_size before and after this PR

ankith@AnkithLaptop:~$ py -m timeit -s "import pygame; s = pygame.Surface((500, 500))" "s.get_size()"
pygame-ce 2.5.0.dev3 (SDL 2.28.3, Python 3.11.6)
5000000 loops, best of 5: 42.5 nsec per loop
ankith@AnkithLaptop:~$ py -m timeit -s "import pygame; s = pygame.Surface((500, 500))" "s.get_size()"
pygame-ce 2.5.0.dev1 (SDL 2.28.3, Python 3.11.6)
10000000 loops, best of 5: 33.7 nsec per loop

A nice decent 20% speedup, but these function operate on the nanosecond scale so still a micro optimization.

I was also curious how this affects wheel size, as we are replacing a simple function call with a semi big inline function in many places, and locally I observe a 1KB increase (in the compressed wheel size). Which is higher than I expected, but also not significant at the same time.

LGTM, thanks for the PR 🎉

Copy link
Member

@zoldalma999 zoldalma999 left a comment

Choose a reason for hiding this comment

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

LGTM!

@zoldalma999 zoldalma999 merged commit 3072e52 into pygame-community:main Apr 26, 2024
39 checks passed
@itzpr3d4t0r itzpr3d4t0r deleted the swap_PyBuildValues branch May 3, 2024 14:44
@ankith26 ankith26 added this to the 2.5.0 milestone Jun 11, 2024
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants