mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
bpo-44337: Shrink the LOAD_ATTR/STORE_ATTR caches (GH-31517)
This commit is contained in:
parent
78859e58e4
commit
281ea9c391
4 changed files with 36 additions and 43 deletions
|
@ -1450,11 +1450,10 @@ eval_frame_handle_pending(PyThreadState *tstate)
|
|||
#define LOAD_MODULE_ATTR_OR_METHOD(attr_or_method) \
|
||||
SpecializedCacheEntry *caches = GET_CACHE(); \
|
||||
_PyAdaptiveEntry *cache0 = &caches[0].adaptive; \
|
||||
_PyAttrCache *cache1 = &caches[-1].attr; \
|
||||
DEOPT_IF(!PyModule_CheckExact(owner), LOAD_##attr_or_method); \
|
||||
PyDictObject *dict = (PyDictObject *)((PyModuleObject *)owner)->md_dict; \
|
||||
assert(dict != NULL); \
|
||||
DEOPT_IF(dict->ma_keys->dk_version != cache1->dk_version_or_hint, \
|
||||
DEOPT_IF(dict->ma_keys->dk_version != cache0->version, \
|
||||
LOAD_##attr_or_method); \
|
||||
assert(dict->ma_keys->dk_kind == DICT_KEYS_UNICODE); \
|
||||
assert(cache0->index < dict->ma_keys->dk_nentries); \
|
||||
|
@ -3452,9 +3451,8 @@ handle_eval_breaker:
|
|||
PyTypeObject *tp = Py_TYPE(owner);
|
||||
SpecializedCacheEntry *caches = GET_CACHE();
|
||||
_PyAdaptiveEntry *cache0 = &caches[0].adaptive;
|
||||
_PyAttrCache *cache1 = &caches[-1].attr;
|
||||
assert(cache1->tp_version != 0);
|
||||
DEOPT_IF(tp->tp_version_tag != cache1->tp_version, LOAD_ATTR);
|
||||
assert(cache0->version != 0);
|
||||
DEOPT_IF(tp->tp_version_tag != cache0->version, LOAD_ATTR);
|
||||
assert(tp->tp_dictoffset < 0);
|
||||
assert(tp->tp_flags & Py_TPFLAGS_MANAGED_DICT);
|
||||
PyDictValues *values = *_PyObject_ValuesPointer(owner);
|
||||
|
@ -3486,15 +3484,14 @@ handle_eval_breaker:
|
|||
PyTypeObject *tp = Py_TYPE(owner);
|
||||
SpecializedCacheEntry *caches = GET_CACHE();
|
||||
_PyAdaptiveEntry *cache0 = &caches[0].adaptive;
|
||||
_PyAttrCache *cache1 = &caches[-1].attr;
|
||||
assert(cache1->tp_version != 0);
|
||||
DEOPT_IF(tp->tp_version_tag != cache1->tp_version, LOAD_ATTR);
|
||||
assert(cache0->version != 0);
|
||||
DEOPT_IF(tp->tp_version_tag != cache0->version, LOAD_ATTR);
|
||||
assert(tp->tp_flags & Py_TPFLAGS_MANAGED_DICT);
|
||||
PyDictObject *dict = *(PyDictObject **)_PyObject_ManagedDictPointer(owner);
|
||||
DEOPT_IF(dict == NULL, LOAD_ATTR);
|
||||
assert(PyDict_CheckExact((PyObject *)dict));
|
||||
PyObject *name = GETITEM(names, cache0->original_oparg);
|
||||
uint32_t hint = cache1->dk_version_or_hint;
|
||||
uint16_t hint = cache0->index;
|
||||
DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, LOAD_ATTR);
|
||||
PyDictKeyEntry *ep = DK_ENTRIES(dict->ma_keys) + hint;
|
||||
DEOPT_IF(ep->me_key != name, LOAD_ATTR);
|
||||
|
@ -3514,9 +3511,8 @@ handle_eval_breaker:
|
|||
PyTypeObject *tp = Py_TYPE(owner);
|
||||
SpecializedCacheEntry *caches = GET_CACHE();
|
||||
_PyAdaptiveEntry *cache0 = &caches[0].adaptive;
|
||||
_PyAttrCache *cache1 = &caches[-1].attr;
|
||||
assert(cache1->tp_version != 0);
|
||||
DEOPT_IF(tp->tp_version_tag != cache1->tp_version, LOAD_ATTR);
|
||||
assert(cache0->version != 0);
|
||||
DEOPT_IF(tp->tp_version_tag != cache0->version, LOAD_ATTR);
|
||||
char *addr = (char *)owner + cache0->index;
|
||||
res = *(PyObject **)addr;
|
||||
DEOPT_IF(res == NULL, LOAD_ATTR);
|
||||
|
@ -3553,9 +3549,8 @@ handle_eval_breaker:
|
|||
PyTypeObject *tp = Py_TYPE(owner);
|
||||
SpecializedCacheEntry *caches = GET_CACHE();
|
||||
_PyAdaptiveEntry *cache0 = &caches[0].adaptive;
|
||||
_PyAttrCache *cache1 = &caches[-1].attr;
|
||||
assert(cache1->tp_version != 0);
|
||||
DEOPT_IF(tp->tp_version_tag != cache1->tp_version, STORE_ATTR);
|
||||
assert(cache0->version != 0);
|
||||
DEOPT_IF(tp->tp_version_tag != cache0->version, STORE_ATTR);
|
||||
assert(tp->tp_flags & Py_TPFLAGS_MANAGED_DICT);
|
||||
PyDictValues *values = *_PyObject_ValuesPointer(owner);
|
||||
DEOPT_IF(values == NULL, STORE_ATTR);
|
||||
|
@ -3581,15 +3576,14 @@ handle_eval_breaker:
|
|||
PyTypeObject *tp = Py_TYPE(owner);
|
||||
SpecializedCacheEntry *caches = GET_CACHE();
|
||||
_PyAdaptiveEntry *cache0 = &caches[0].adaptive;
|
||||
_PyAttrCache *cache1 = &caches[-1].attr;
|
||||
assert(cache1->tp_version != 0);
|
||||
DEOPT_IF(tp->tp_version_tag != cache1->tp_version, STORE_ATTR);
|
||||
assert(cache0->version != 0);
|
||||
DEOPT_IF(tp->tp_version_tag != cache0->version, STORE_ATTR);
|
||||
assert(tp->tp_flags & Py_TPFLAGS_MANAGED_DICT);
|
||||
PyDictObject *dict = *(PyDictObject **)_PyObject_ManagedDictPointer(owner);
|
||||
DEOPT_IF(dict == NULL, STORE_ATTR);
|
||||
assert(PyDict_CheckExact((PyObject *)dict));
|
||||
PyObject *name = GETITEM(names, cache0->original_oparg);
|
||||
uint32_t hint = cache1->dk_version_or_hint;
|
||||
uint16_t hint = cache0->index;
|
||||
DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, STORE_ATTR);
|
||||
PyDictKeyEntry *ep = DK_ENTRIES(dict->ma_keys) + hint;
|
||||
DEOPT_IF(ep->me_key != name, STORE_ATTR);
|
||||
|
@ -3616,9 +3610,8 @@ handle_eval_breaker:
|
|||
PyTypeObject *tp = Py_TYPE(owner);
|
||||
SpecializedCacheEntry *caches = GET_CACHE();
|
||||
_PyAdaptiveEntry *cache0 = &caches[0].adaptive;
|
||||
_PyAttrCache *cache1 = &caches[-1].attr;
|
||||
assert(cache1->tp_version != 0);
|
||||
DEOPT_IF(tp->tp_version_tag != cache1->tp_version, STORE_ATTR);
|
||||
assert(cache0->version != 0);
|
||||
DEOPT_IF(tp->tp_version_tag != cache0->version, STORE_ATTR);
|
||||
char *addr = (char *)owner + cache0->index;
|
||||
STAT_INC(STORE_ATTR, hit);
|
||||
STACK_SHRINK(1);
|
||||
|
@ -4416,7 +4409,7 @@ handle_eval_breaker:
|
|||
assert(self_cls->tp_flags & Py_TPFLAGS_MANAGED_DICT);
|
||||
PyDictObject *dict = *(PyDictObject**)_PyObject_ManagedDictPointer(self);
|
||||
DEOPT_IF(dict != NULL, LOAD_METHOD);
|
||||
DEOPT_IF(((PyHeapTypeObject *)self_cls)->ht_cached_keys->dk_version != cache1->dk_version_or_hint, LOAD_METHOD);
|
||||
DEOPT_IF(((PyHeapTypeObject *)self_cls)->ht_cached_keys->dk_version != cache1->dk_version, LOAD_METHOD);
|
||||
STAT_INC(LOAD_METHOD, hit);
|
||||
PyObject *res = cache2->obj;
|
||||
assert(res != NULL);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue