GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-124153: Clean up workarounds for `PyType_GetBaseByToken()` performance by neonene · Pull Request #124323 · python/cpython

Conversation

@neonene

@neonene neonene commented Sep 23, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This moves down PyType_GetBaseByToken()'s sub functions in typeobject.c.

Regarding MSVC, most of the PGO performance depends on the initial layout of *.obj file compiled at the collection phase (PGInsturment). Hopefully, PyType_GetBaseByToken() could have a stable performance, once we find a good formation of the family, as the performance defference between 3.9 and 3.10.X, which has come from the ceval.c layout, is still constant in a good PGO health.

Without this, any functions in typeobject.c can be slower if they have a similar branch:

if (!_PyType_HasFeature(foo, Py_TPFLAGS_HEAPTYPE)) {
    ...
} 
...  // no else

Currently, PyType_GetSlot(), PyType_GetModule() and PyType_GetModuleBydef() have it as well as the family. PyType_GetModuleBydef() actually misses about 10% on the telco benchmark.

If this patch is too OS specific, alternative ways to recover the PyType_GetModuleBydef() performance would be:

  • Make _PyType_HasFeature() an alias of PyType_HasFeature().
  • Use if-else in the loop, which needs to be checked after _PyType_GetModuleBydef2() is removed.
  • Issue: Add PyType_GetBaseByToken function with Py_tp_token slot #124153

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
neonene added 5 commits September 23, 2024 08:37
@neonene
abandon if-else chains for maintainability
04b2381
@neonene
add forward declarations
c2cabd1
The order might have a very slight effect.
@neonene
move down get_base_by_token_from_mro()
ead4411
@neonene
move down check_base_by_token()
7349f97
@neonene
move down get_base_by_token_recursive()
f938abc
@neonene
neonene requested a review from markshannon as a code owner September 23, 2024 00:36
@bedevere-app bedevere-app Bot added the awaiting review label Sep 23, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Sep 23, 2024
Add PyType_GetBaseByToken function with Py_tp_token slot #124153
Closed
6 tasks done
@neonene neonene mentioned this pull request Sep 23, 2024
gh-124153: Remove _PyType_GetModuleByDef2 private function #124261
Merged
rruuaanng
rruuaanng reviewed Sep 23, 2024
View reviewed changes
Comment thread Objects/typeobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@neonene
add again a comment about gotos
516d2fb
@neonene

neonene commented Sep 23, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I'll check if it is good to to put PyType_GetBaseByToken() family above the PyType_GetModuleBydef() without the forward declarations.

UPDATE: The ugly order below improved the performance, but it was my silly idea to try to rely on unrelated functions.

 PyType_GetModuleState()
 
+get_base_by_token_recursive()
+get_base_by_token_from_mro()
+check_base_by_token()
+PyType_GetBaseByToken()
 
 PyType_GetModuleByDef()
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@neonene
neonene marked this pull request as draft September 24, 2024 08:07
@bedevere-app bedevere-app Bot removed the awaiting review label Sep 24, 2024
@neonene
Merge branch 'main' into bytokens
3783982
@neonene

neonene commented Sep 24, 2024

Copy link
Copy Markdown
Contributor Author

I'll make an alternative PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@neonene neonene closed this Sep 24, 2024
@neonene neonene mentioned this pull request Sep 25, 2024
gh-124153: Fix unstable optimization of PyType_GetBaseByToken() and friends #124488
Merged
@neonene
neonene deleted the bytokens branch September 26, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
1 more reviewer
@rruuaanng rruuaanng rruuaanng left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@neonene @rruuaanng
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.