Skip to content

Commit 9601b08

Browse files
committed
Rearrange cache for LOAD_ATTR_PROPERTY
1 parent 1402714 commit 9601b08

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

Include/internal/pycore_code.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,15 @@ typedef struct {
7474
uint16_t descr[4];
7575
} _PyLoadMethodCache;
7676

77+
typedef struct {
78+
uint16_t counter;
79+
uint16_t type_version[2];
80+
uint16_t func[4];
81+
uint16_t func_version[2];
82+
} _PyLoadPropertyCache;
83+
7784

78-
// MUST be the max(_PyAttrCache, _PyLoadMethodCache)
85+
// MUST be max(_PyAttrCache, _PyLoadMethodCache, _PyLoadPropertyCache)
7986
#define INLINE_CACHE_ENTRIES_LOAD_ATTR CACHE_ENTRIES(_PyLoadMethodCache)
8087

8188
#define INLINE_CACHE_ENTRIES_STORE_ATTR CACHE_ENTRIES(_PyAttrCache)

Python/bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ dummy_func(
19921992
unused/2 +
19931993
_LOAD_ATTR_CLASS;
19941994

1995-
inst(LOAD_ATTR_PROPERTY, (unused/1, type_version/2, func_version/2, fget/4, owner -- unused, unused if (0))) {
1995+
inst(LOAD_ATTR_PROPERTY, (unused/1, type_version/2, fget/4, func_version/2, owner -- unused, unused if (0))) {
19961996
assert((oparg & 1) == 0);
19971997
DEOPT_IF(tstate->interp->eval_frame);
19981998

Python/generated_cases.c.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/specialize.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name)
887887
}
888888
case PROPERTY:
889889
{
890-
_PyLoadMethodCache *lm_cache = (_PyLoadMethodCache *)(instr + 1);
890+
_PyLoadPropertyCache *lm_cache = (_PyLoadPropertyCache *)(instr + 1);
891891
assert(Py_TYPE(descr) == &PyProperty_Type);
892892
PyObject *fget = ((_PyPropertyObject *)descr)->prop_get;
893893
if (fget == NULL) {
@@ -913,11 +913,10 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name)
913913
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_OTHER);
914914
goto fail;
915915
}
916-
write_u32(lm_cache->keys_version, version);
917916
assert(type->tp_version_tag != 0);
918917
write_u32(lm_cache->type_version, type->tp_version_tag);
919-
/* borrowed */
920-
write_obj(lm_cache->descr, fget);
918+
write_obj(lm_cache->func, fget); // borrowed
919+
write_u32(lm_cache->func_version, version);
921920
instr->op.code = LOAD_ATTR_PROPERTY;
922921
goto success;
923922
}

0 commit comments

Comments
 (0)