Skip to content

Make intern! & py_format! strings immortal#5794

Draft
bschoenmaeckers wants to merge 3 commits intoPyO3:mainfrom
bschoenmaeckers:intern-immortal
Draft

Make intern! & py_format! strings immortal#5794
bschoenmaeckers wants to merge 3 commits intoPyO3:mainfrom
bschoenmaeckers:intern-immortal

Conversation

@bschoenmaeckers
Copy link
Member

No description provided.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 11, 2026

Merging this PR will not alter performance

✅ 100 untouched benchmarks


Comparing bschoenmaeckers:intern-immortal (bb3f570) with main (46c16e4)

Open in CodSpeed

@ngoldbaum
Copy link
Contributor

If you're interested in making things immortal, Python 3.15 will have PyUnstable_SetImmortal, which will allow you to do this with arbitrary objects.

There's also a backport we can adapt for Python 3.13 and 3.14: python/pythoncapi-compat#164

@bschoenmaeckers
Copy link
Member Author

If you're interested in making things immortal, Python 3.15 will have PyUnstable_SetImmortal, which will allow you to do this with arbitrary objects.

There's also a backport we can adapt for Python 3.13 and 3.14: python/pythoncapi-compat#164

The following docs suggest that you should not use it on strings.

https://github.com/python/cpython/blob/aa8a43d179bad5cd9fbfce63b630e2ee0bd617e4/InternalDocs/string_interning.md?plain=1#L57

@ngoldbaum
Copy link
Contributor

Sorry, I wasn't trying to say it would be useful here, just as a more general comment.

@bschoenmaeckers
Copy link
Member Author

Not sure if this has any positive effect on performance.

@ngoldbaum
Copy link
Contributor

In my experience refcount churn isn't usually a big performance cost. The exception is if an object is shared on the free-threaded build, because inrefs and decrefs on shared objects are substantially more expensive than unshared objects.

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

Comments