Skip to content

Comments

gh-139103: Improve enum free-threaded scaling#144977

Draft
colesbury wants to merge 1 commit intopython:mainfrom
colesbury:gh-139103-enum-scaling
Draft

gh-139103: Improve enum free-threaded scaling#144977
colesbury wants to merge 1 commit intopython:mainfrom
colesbury:gh-139103-enum-scaling

Conversation

@colesbury
Copy link
Contributor

@colesbury colesbury commented Feb 18, 2026

This is a draft PR showing how we can improve enum scaling. It requires enabling deferred reference counting on objects from Python. That will probably be split out into a separate PR and issue.

Copy link
Member

@Yhg1s Yhg1s left a comment

Choose a reason for hiding this comment

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

Didn't we talk about making module globals automatically use deferred refcounts before, and wouldn't that fix the majority of the uses of enum?

Comment on lines +1065 to +1066
contention on objects that are shared between multiple threads.
[clinic start generated code]*/
Copy link
Member

Choose a reason for hiding this comment

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

This could do with a little bit of an explanation what effect this'll have on the object lifetime.

_cls_type = None

def __init__(self, fget=None, fset=None, fdel=None, doc=None):
sys._enable_deferred_refcount(self)
Copy link
Member

Choose a reason for hiding this comment

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

This probably deserves a specific comment on why this matters.

@colesbury
Copy link
Contributor Author

I think @nascheme already made that change. LOAD_ATTR and LOAD_GLOBAL enable deferred reference counting on the object if it's not owned by the current thread.

maybe_enable_deferred_ref_count(value);

It doesn't fix this issue because of how enum attributes are implemented. Maybe there's a way to extend that logic so that it covers the enum case?

Sign up for free to 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