Description
Add specialization "families" for PEP 659 adaptive interpreter for LOAD_METHOD
.
Background:
LOAD_METHOD
is a compiler-level specialization of LOAD_ATTR
. It's emitted with CALL_METHOD
for calls of the form o.meth()
, where o
is not a top-level import. When this was added in 3.7, it brought 20% faster method calls by avoiding creating a bound method object.
Specialization
The specialization families for LOAD_METHOD
are very similar to LOAD_ATTR
(#52) and we can reuse many ideas and code. The speedup comes from avoiding a _PyObject_GetMethod
which does two things:
_PyType_Lookup
(walk the MRO)- Check if
meth
is ino.__dict__
to make sure it's not an attribute.
There are one or two specializations which I'm optimistic for:
renamed toLOAD_METHOD_WITH_HINT
(seeLOAD_ATTR_WITH_HINT
)LOAD_METHOD_CACHED
-- cache the descriptor object- Optional:
LOAD_METHOD_WITH_HINT_NO_DICT
-- specialized form ofLOAD_METHOD_WITH_HINT
for objects with no__dict__
These specializations make sense, but will likely bring little speedup in macrobenchmarks, so we need more profiling:
LOAD_METHOD_MODULE
--o
is a module, almost same as specializingLOAD_ATTR_MODULE
LOAD_METHOD_CLASS
--o
is a class andmeth
is a classmethod
Also, I don't expect much speedups for builtin methods (e.g {1,2,3}.keys()
). Their _PyType_Lookup
should be cheap due to the existing type method cache. Classes with a long MRO will probably benefit the most.
Workbranch: python/cpython#27722