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 in o.__dict__ to make sure it's not an attribute.
There are one or two specializations which I'm optimistic for:
LOAD_METHOD_WITH_HINT (see LOAD_ATTR_WITH_HINT) renamed to LOAD_METHOD_CACHED -- cache the descriptor object
- Optional:
LOAD_METHOD_WITH_HINT_NO_DICT -- specialized form of LOAD_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 specializing LOAD_ATTR_MODULE
LOAD_METHOD_CLASS -- o is a class and meth 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
Add specialization "families" for PEP 659 adaptive interpreter for
LOAD_METHOD.Background:
LOAD_METHODis a compiler-level specialization ofLOAD_ATTR. It's emitted withCALL_METHODfor calls of the formo.meth(), whereois 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_METHODare very similar toLOAD_ATTR(#52) and we can reuse many ideas and code. The speedup comes from avoiding a_PyObject_GetMethodwhich does two things:_PyType_Lookup(walk the MRO)methis 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 objectLOAD_METHOD_WITH_HINT_NO_DICT-- specialized form ofLOAD_METHOD_WITH_HINTfor objects with no__dict__These specializations make sense, but will likely bring little speedup in macrobenchmarks, so we need more profiling:
LOAD_METHOD_MODULE--ois a module, almost same as specializingLOAD_ATTR_MODULELOAD_METHOD_CLASS--ois a class andmethis a classmethodAlso, I don't expect much speedups for builtin methods (e.g
{1,2,3}.keys()). Their_PyType_Lookupshould be cheap due to the existing type method cache. Classes with a long MRO will probably benefit the most.Workbranch: python/cpython#27722