FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[mypyc] Intern a few more strings by cdce8p · Pull Request #20537 · python/mypy · GitHub

Repository navigation

[mypyc] Intern a few more strings - #20537

Merged
ilevkivskyi merged 1 commit into
python:masterfrom
cdce8p:mypyc-intern-strings
Jan 10, 2026
Merged

ilevkivskyi merged 1 commit into
python:masterfrom
cdce8p:mypyc-intern-strings

Conversation

cdce8p commented Jan 6, 2026

Copy link
Copy Markdown
Collaborator

Followup to #20460

cdce8p added the topic-mypyc mypyc bugs label Jan 6, 2026
Comment on lines 450 to 454
PyInit_strings(void)
{
intern_strings();
return PyModuleDef_Init(&librt_strings_module);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

A few of the changed functions changed here are also called by librt. Therefore we need to initialize them here as well, not just for mypyc.

Technically this is a small performance penalty for other projects which only rely on librt. If that's relevant, we could consider separating the strings used by just mypyc and those used by both mypyc and librt.

Overall this will likely still be a net improvement though, since the strings are initialized / converted to a PyObject only once instead of for each function call.

/CC @ilevkivskyi

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What is the expected order of magnitude of the penalty? If it is under 1ms I think it is OK.

Also cc @JukkaL for visibility.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

(to be clear my question is specifically about import time, not the net performance)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Not sure tbh, though all the function does is create a PyObject for each string in static_data.c and immortalize it. https://github.com/python/mypy/blob/master/mypyc/lib-rt/static_data.c

https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_InternFromString

ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think this is OK (and I didn't see any objections).

ilevkivskyi merged commit 2322834 into python:master Jan 10, 2026
16 checks passed
cdce8p deleted the mypyc-intern-strings branch January 10, 2026 05:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic-mypyc mypyc bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL