Author georg.brandl
Recipients georg.brandl, ncoghlan, pitrou
Date 2014-10-02.11:39:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1412249952.63.0.934537522507.issue22540@psf.upfronthosting.co.za>
In-reply-to
Content
With the introduction of ABCs, PyObject_IsInstance (and for this issue, everything is also valid for PyObject_IsSubclass) has to check for a type's __instancecheck__ before falling back to the built-in behavior.

However, the "type" type has an __instancecheck__ method (that calls the built-in behavior too), probably for consistency on the Python side.

This means that the fast path is never taken, and every isinstance() call is slowed down unnecessarily.

This patch introduces a new fast path by checking for PyType_Type exactly before looking up the __instancecheck__.

It also introduces a check for exact match in PyObject_IsSubclass() analogous to one that is already present in PyObject_IsInstance().  Note that this will break __subclasscheck__ implementations that would deny issubclass(C, C).

This patch is not only useful for speeding up isinstance() and issubclass() calls, but also has other effects such as not slowing down the improvement of issue #12029.
History
Date User Action Args
2014-10-02 11:39:12georg.brandlsetrecipients: + georg.brandl, ncoghlan, pitrou
2014-10-02 11:39:12georg.brandlsetmessageid: <1412249952.63.0.934537522507.issue22540@psf.upfronthosting.co.za>
2014-10-02 11:39:12georg.brandllinkissue22540 messages
2014-10-02 11:39:12georg.brandlcreate