On Sat., 21 Sep. 2019, 5:28 am Vinay Sajip via Python-Dev, < python-dev@python.org> wrote:
> I just ran an analysis of static variable definitions in CPython code, > using clang, on Ubuntu and Windows. The results should be available here: > > https://cpython.red-dove.com/ > > As I understand it, _Py_IDENTIFIER instances are supposed to hold constant > strings that are used in Python - e.g. "__class__", "__dict__" and so on. I > noticed that there are numerous duplicates of these - e.g. 8 instances of > __name__, 11 instances of __dict__, and so on - each instance is defined as > static in its source file and so completely distinct from the others. > > I realise the overall amount of memory used by these structures isn't > large, but is there any particular benefit to having these multiple copies? > The current situation seems a little untidy, at least. What would be the > disadvantage of making them extern in the headers and allocating them once > in some consts.c module? After all, they seem for the most part to be > well-known constant strings that don't need to be encapsulated in any > particular C compilation unit. > Moving some of the especially common identifier references into the interpreter state struct may make sense. Adding more process globals wouldn't be desirable though, as they're one of the more common ways of breaking encapsulation between subinterpreters (hence Eric's efforts to eliminate as many of them as he reasonably can). Cheers, Nick. >
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/IVMLDHZOE2WCGYA5PZQ24R3PYBQEUVXH/