[issue42115] Caching infrastructure for the evaluation loop: specialised opcodes
Guido van Rossum
report at bugs.python.org
Fri Jan 29 12:31:14 EST 2021
Guido van Rossum <guido at python.org> added the comment:
I had a simpler idea for an inline cache for LOAD_METHOD than GH-23503. The essential part goes like this (sorry for the hybrid C/Python):
if <optimized etc.>:
if type == lm->type and type->tp_version_tag == lm->tp_version_tag:
meth = lm->meth
SET_TOP(meth)
PUSH(obj)
DISPATCH()
name = GETITEM(names, oparg)
meth_found = _PyObject_GetMethod(obj, name, &meth)
<error check>
if meth_found:
SET_TOP(meth)
PUSH(obj)
if <optimizing etc.>:
lm = ...
lm->type = type
lm->meth = meth
<etc.>
What am I missing? Why is the hash of the name needed?
Oh, it's probably because there could still be an overriding value in obj.__dict__. But certainly we could check for type == lm->type before the other checks (HasFeature and tp_version_tag).
But what if we only did this for classes without an instance dict? That could work for things like list.append and str.find.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42115>
_______________________________________
More information about the Python-bugs-list
mailing list