-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
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.
microbenchmark
python -m pyperf timeit -s '
import _testcapi
hasattr_string = _testcapi.hasattr_string
class A:
def __init__(self):
self.attr = 1
a = A()' 'hasattr_string(a, "noattr")'
.....................
Mean +- std dev: 487 ns +- 7 ns
Linked PRs
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement