>From my understanding, _Py_IDENTIFIER was designed for static usage.
The overhead is quite low; keeping it as a private (static)
module-level internal variable helps to decouple things.
This target is very important for keeping public API as small as possible.

On Fri, Sep 20, 2019 at 10:32 PM 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.
>
> Regards,
>
> Vinay Sajip
> _______________________________________________
> 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/GVQOMWXUDYLBXZ2MMIDX5D6X7X42VQV7/



-- 
Thanks,
Andrew Svetlov
_______________________________________________
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/E24YQUYJMXC4LZXZEU7YELWIDDVWBDF3/

Reply via email to