Skip to content

Conversation

@cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented Jan 6, 2026

Followup to #20460

@cdce8p 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
Collaborator Author

Choose a reason for hiding this comment

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

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
Member

Choose a reason for hiding this comment

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

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
Member

Choose a reason for hiding this comment

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

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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

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