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

bpo-37543: optimize pymalloc #14674

Merged
merged 8 commits into from Jul 17, 2019
Merged

bpo-37543: optimize pymalloc #14674

merged 8 commits into from Jul 17, 2019

Conversation

methane
Copy link
Member

@methane methane commented Jul 9, 2019

PyObject_Malloc() and PyObject_Free() inlines pymalloc_alloc and
pymalloc_free partially.
But when PGO is not used, the compiler doesn't know where is the hot part
in pymalloc_alloc and pymalloc_free.

To help compilers:

  • use LIKELY/UNLIKELY macros
  • mark pymalloc_alloc and pymalloc_free as inline function
  • split slow / rare parts into other functions
# bm_spectral_norm
Mean +- std dev: [master] 199 ms +- 1 ms -> [patched] 176 ms +- 1 ms: 1.13x faster (-11%)

https://bugs.python.org/issue37543

PyObject_Malloc() and PyObject_Free() inlines pymalloc_alloc and
pymalloc_free partially.
But when PGO is not used, compiler don't know where is the hot part
in pymalloc_alloc and pymalloc_free.
@methane methane changed the title optimize pymalloc bpo-37543: optimize pymalloc Jul 10, 2019
@methane methane added performance Performance or resource usage and removed DO-NOT-MERGE labels Jul 10, 2019
@tim-one tim-one self-requested a review July 10, 2019 14:49
Copy link
Member

@tim-one tim-one left a comment

Choose a reason for hiding this comment

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

Very nice! It's lovely to see the main functions cut down to something understandable 😄 Just have some minor comments.

Objects/obmalloc.c Outdated Show resolved Hide resolved
Objects/obmalloc.c Outdated Show resolved Hide resolved
@methane methane marked this pull request as ready for review July 12, 2019 13:38
@methane methane merged commit fb26504 into python:master Jul 17, 2019
@bedevere-bot
Copy link

@methane: Please replace # with GH- in the commit message next time. Thanks!

@methane methane deleted the optimize-pymalloc branch July 17, 2019 12:24
@jdemeyer
Copy link
Contributor

Did you putting the macros LIKELY and UNLIKELY in a public header file (renaming them of course)? There are surely other places in CPython that could benefit from them.

@methane
Copy link
Member Author

methane commented Jul 19, 2019

I did not it, but I will do it when I want to use it in other places.

lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
PyObject_Malloc() and PyObject_Free() inlines pymalloc_alloc and
pymalloc_free partially.
But when PGO is not used, compiler don't know where is the hot part
in pymalloc_alloc and pymalloc_free.
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
PyObject_Malloc() and PyObject_Free() inlines pymalloc_alloc and
pymalloc_free partially.
But when PGO is not used, compiler don't know where is the hot part
in pymalloc_alloc and pymalloc_free.
websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request Jul 20, 2020
PyObject_Malloc() and PyObject_Free() inlines pymalloc_alloc and
pymalloc_free partially.
But when PGO is not used, compiler don't know where is the hot part
in pymalloc_alloc and pymalloc_free.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants