-
Notifications
You must be signed in to change notification settings - Fork 53
Specialize LOAD_METHOD #81
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
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 object- Optional:
LOAD_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 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