PERF Don't format attribute error in JsProxy_GetAttr (#4961)

This initial `PyObject_GenericGetAttr` is expected to fail, but it formats an
expensive AttributeError whenever it does. The internal method
`_PyObject_GenericGetAttrWithDict` has a `suppress` argument that makes it not
do this.

This saves between 40% and 70% of the time spent in JsProxy_GetAttr depending
on the return value.
This commit is contained in:
Hood Chatham 2024-07-25 15:12:27 +02:00 committed by GitHub
parent 96dde9d04c
commit 2287b0a45d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 3 deletions

View File

@ -371,11 +371,10 @@ EM_JS_VAL(JsVal, JsProxy_GetAttr_js, (JsVal jsobj, const char* ptrkey), {
static PyObject*
JsProxy_GetAttr(PyObject* self, PyObject* attr)
{
PyObject* result = PyObject_GenericGetAttr(self, attr);
if (result != NULL || !PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyObject* result = _PyObject_GenericGetAttrWithDict(self, attr, NULL, 1);
if (result != NULL || PyErr_Occurred()) {
return result;
}
PyErr_Clear();
bool success = false;
JsVal jsresult = JS_NULL;