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-127773: Disable attribute cache on incompatible MRO entries by encukou · Pull Request #127924 · python/cpython

Conversation

@encukou

@encukou encukou commented Dec 13, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

This brings back the functionality of Py_TPFLAGS_HAVE_VERSION_TAG, which should have been named “use version tag”, as the field itself is always present -- see #27260 where I mistakenly removed it.

The type attribute cache relies on a class being able to invalidate caches of all of its subclasses. If a type's MRO contains an entry that's not that type's base, the cache needs to be disabled.
This requires a single bit, which was in tp_flags in 3.9 and below.

I'd like to avoid using tp_flags for an internal flag (even one that's currently reserved for ABI compatibility).

We already have a mechanism for disabling the cache: it's disabled after 1000 modifications to a single type, using tp_versions_used as a counter. It would be possible to set this to 1000 (MAX_VERSIONS_PER_CLASS) when an incompatible MRO is found. To make the code & logic more understandable, this PR uses a new bigger constant, _Py_ATTR_CACHE_UNUSED. The existing tp_versions_used check is reused.

If the tp_versions_used mechanism is dropped in the future, _Py_ATTR_CACHE_UNUSED can become a single bit stored elsewhere in PyTypeObject. Ideally in a private (underscore-prefixed) field; not in tp_flags.

@markshannon @colesbury Does this sound right? I'm not much of an attribute cache expert and I don't know about future plans in this area.

  • Issue: Stale entries in MRO cache if MRO contains non-base classes #127773

Sorry, something went wrong.

Uh oh!

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

All reactions
encukou added 2 commits December 13, 2024 15:47
@encukou
Add test
6653d17
@encukou
Set large tp_versions_used when type attribute cache should be disa…
1d7a635
…bled
@encukou
encukou requested a review from colesbury December 13, 2024 15:13
@encukou
encukou requested a review from markshannon as a code owner December 13, 2024 15:13
@bedevere-app bedevere-app Bot mentioned this pull request Dec 13, 2024
Stale entries in MRO cache if MRO contains non-base classes #127773
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Dec 13, 2024
colesbury
colesbury approved these changes Dec 13, 2024
View reviewed changes

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This makes sense to me, but @markshannon is probably more familiar with the MRO cache and tp_versions_used.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Objects/typeobject.c Resolved

Uh oh!

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

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Dec 13, 2024
Eclips4
Eclips4 reviewed Dec 13, 2024
View reviewed changes
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2024-12-13-15-21-45.gh-issue-127773.E-DZR4.rst Resolved

Uh oh!

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

encukou and others added 4 commits December 16, 2024 16:00
@encukou @Eclips4
Link a term in the blurb
b649a96
Co-authored-by: Kirill Podoprigora <[email protected]>
@encukou
Use static_assert
d69ec0f
We define `static_assert` in `pymacro.h`.
@encukou
Merge in the main branch
a537cc3
@encukou
Use #if and #error
5dbbdf4
@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Dec 17, 2024
@bedevere-bot

bedevere-bot commented Dec 17, 2024

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit 5dbbdf4 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Dec 17, 2024
@encukou

encukou commented Dec 18, 2024

Copy link
Copy Markdown
Member Author

The issues on failed buildbots are unrelated (the ctypes one on RHEL8 is fixed in #128034).

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou

encukou commented Dec 18, 2024

Copy link
Copy Markdown
Member Author

@markshannon, do you want to take a look?

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou

encukou commented Jan 7, 2025

Copy link
Copy Markdown
Member Author

If there are no objections, I'll merge this next week.

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou
encukou merged commit aa6579c into python:main Jan 13, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Jan 13, 2025
@encukou
encukou deleted the stale-mro-cache branch January 20, 2025 16:52
encukou added a commit to encukou/cpython that referenced this pull request Jan 12, 2026
@encukou
pythongh-127773: Disable attribute cache on incompatible MRO entries (p…
356fb83
…ythonGH-127924)
@bedevere-app

bedevere-app Bot commented Jan 12, 2026

Copy link
Copy Markdown

GH-143729 is a backport of this pull request to the 3.13 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

encukou added a commit that referenced this pull request Jan 26, 2026
@encukou
[3.13] gh-127773: Disable attribute cache on incompatible MRO entries (…
fdac87a
…GH-127924) (GH-143729)
@xmo-odoo xmo-odoo mentioned this pull request Jul 10, 2026
[PERF] core: restore model getattr perfs in python 3.13 odoo/odoo#275640
Closed
@perrinjerome perrinjerome mentioned this pull request Aug 20, 2026
Types with mro() unconditionally disables type attribute cache, causing performance regression for compatible MRO implementations, such as Zope #156096
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Eclips4 Eclips4 Eclips4 left review comments
@colesbury colesbury colesbury approved these changes
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

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.

4 participants

@encukou @bedevere-bot @colesbury @Eclips4
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.