On Thu, Feb 3, 2022 at 11:49 PM Eric Snow <ericsnowcurrently@gmail.com> wrote:
I suppose I'd like to know what the value of _Py_IDENTIFIER() is for 3rd party modules.
_Py_IDENTIFIER() API is simple and short, Python creates the Python string object automatically, *and* clears this object at exit. It's convenient. On the other side, functions like PyDict_GetItemString() call PyUnicode_FromString(): it allocates memory on the heap, it decodes the bytes string from UTF-8, and then deallocates the memory. It's inefficient just for a dict lookup. In the _Py_IDENTIFIER() API, _PyUnicode_FromId() calls PyUnicode_InternInPlace() which makes dict lookup even more efficient. Victor -- Night gathers, and now my watch begins. It shall not end until my death.