This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author methane
Recipients levkivskyi, methane
Date 2018-01-13.18:29:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1515868169.96.0.467229070634.issue32544@psf.upfronthosting.co.za>
In-reply-to
Content
ABCMeta.__new__ calls `getattr(value, "__isabstractmethod__", False)` many times.
https://github.com/python/cpython/blob/0f31c74fcfdec8f9e6157de2c366f2273de81677/Lib/abc.py#L135-L142

Since metaclass is used by subclasses, it checks all members of all subclasses (including concrete class).

But getattr() and hasattr() is inefficient when attribution is not found,
because it raises AttributeError and clear it internally.

I tried to bypass AttributeError when tp_getattro == PyObject_GenericGetAttr.
Here is quick micro benchmark:

$ ./python-patched -m perf timeit --compare-to=`pwd`/python-master -s 'def foo(): pass' 'hasattr(foo, "__isabstractmethod__")'python-master: ..................... 385 ns +- 2 ns
python-patched: ..................... 87.6 ns +- 1.6 ns

Mean +- std dev: [python-master] 385 ns +- 2 ns -> [python-patched] 87.6 ns +- 1.6 ns: 4.40x faster (-77%)

(I added Ivan to nosy list because he may implement C version of ABC.)
History
Date User Action Args
2018-01-13 18:29:30methanesetrecipients: + methane, levkivskyi
2018-01-13 18:29:29methanesetmessageid: <1515868169.96.0.467229070634.issue32544@psf.upfronthosting.co.za>
2018-01-13 18:29:29methanelinkissue32544 messages
2018-01-13 18:29:29methanecreate