Skip to content

Make intern! & py_format! strings immortal#5794

Draft
bschoenmaeckers wants to merge 1 commit intoPyO3:mainfrom
bschoenmaeckers:intern-immortal
Draft

Make intern! & py_format! strings immortal#5794
bschoenmaeckers wants to merge 1 commit 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 improve performance by 19.01%

⚡ 1 improved benchmark
✅ 98 untouched benchmarks
⏩ 1 skipped benchmark1

Performance Changes

Benchmark BASE HEAD Efficiency
format_simple 368.6 ns 309.7 ns +19.01%

Comparing bschoenmaeckers:intern-immortal (c244ede) with main (9072f6c)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@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.

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