You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PyObject_HasAttrString is implemented in terms of PyObject_GetAttrString / PyErr_Clear.
for non-existing attributes, there's significant overhead from creating an error only to clear it later.
this can be optimized by implementing it in terms of PyObject_HasAttr.
There appear to be no calls to PyObject_HasAttrString in CPython itself, other than internal extension modules. So it's unlikely there will be an effect on CPython's own performance. However, the function is part of the public API, so speeding it up may help some third-party extensions.
the before and after numbers are quoted in the PR description (the optimization is about 3.3X speedup).
Have you tested the impact on something other than a micro benchmark?
as @JelleZijlstra pointed out, this doesn't really show up within cpython itself. it showed up in Instagram profiling data due to internal and/or third-party usage (I don't have the data available to pinpoint it).
based on code search I see usage of this API in BoostPython & Cython for example.
Activity
pythongh-104078: Improve performance of PyObject_HasAttrString
ericvsmith commentedon May 2, 2023
What are the before and after timings? Have you tested the impact on something other than a micro benchmark?
JelleZijlstra commentedon May 2, 2023
There appear to be no calls to
PyObject_HasAttrStringin CPython itself, other than internal extension modules. So it's unlikely there will be an effect on CPython's own performance. However, the function is part of the public API, so speeding it up may help some third-party extensions.itamaro commentedon May 2, 2023
the before and after numbers are quoted in the PR description (the optimization is about 3.3X speedup).
as @JelleZijlstra pointed out, this doesn't really show up within cpython itself. it showed up in Instagram profiling data due to internal and/or third-party usage (I don't have the data available to pinpoint it).
based on code search I see usage of this API in BoostPython & Cython for example.
gh-104078: Improve performance of PyObject_HasAttrString (#104079)