Skip to content

gh-124153: Implement PyType_GetBaseByToken() and Py_tp_token slot - #124163

Merged
encukou merged 10 commits into
python:mainfrom
neonene:tp_token
Sep 18, 2024
Merged

gh-124153: Implement PyType_GetBaseByToken() and Py_tp_token slot#124163
encukou merged 10 commits into
python:mainfrom
neonene:tp_token

Conversation

@neonene

@neoneneneonene commented Sep 17, 2024

Copy link
Copy Markdown
Contributor

@neonene

Copy link
Copy Markdown
ContributorAuthor

I'll check this and PoC version again.

@encukouencukou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great, thank you!
I have just one style suggestion. But if you'd like to keep it we can merge the PR as it is.

Comment threadObjects/typeobject.c Outdated
Comment threadObjects/typeobject.c Outdated
return -1;
}

if (!_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {

@neoneneneoneneSep 17, 2024

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

When I observed a good performance, the line had a typo (missing a NOT), though check_base_by_token() was unused during a PGO test. The telco got slower by 5-10% once I corrected, which was actually fixed by one of the following:

  • Use if-else statement

  • Replace _PyType_HasFeature() with the public PyType_HasFeature(), not with ineffective (type->tp_flags & Py_TPFLAGS_HEAPTYPE)

They are not used in PyType_GetBaseByToken().

This chains the branches in PyType_GetBaseByToken() as well, which is effective when MSVC is in better condition on PGO.
@neonene

Copy link
Copy Markdown
ContributorAuthor

I think I've finished. When checking a type without a result, this may be a bit slower than the draft PR, not trained well for now.

@encukou
encukou merged commit 646f16b into python:mainSep 18, 2024
@neonene
neonene deleted the tp_token branch September 18, 2024 15:02
@zwarezware mentioned this pull request Sep 18, 2024
savannahostrowski pushed a commit to savannahostrowski/cpython that referenced this pull request Sep 22, 2024
Sign up for freeto 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.

2 participants

@neonene@encukou