Skip to content

Commit 5b3bf78

Browse files
committed
Rearrange cache for LOAD_ATTR_PROPERTY
1 parent 6d0b9cb commit 5b3bf78

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
@@ -2043,7 +2043,7 @@ dummy_func(
20432043
unused/2 +
20442044
_LOAD_ATTR_CLASS;
20452045

2046-
inst(LOAD_ATTR_PROPERTY, (unused/1, type_version/2, func_version/2, fget/4, owner -- unused, unused if (0))) {
2046+
inst(LOAD_ATTR_PROPERTY, (unused/1, type_version/2, fget/4, func_version/2, owner -- unused, unused if (0))) {
20472047
assert((oparg & 1) == 0);
20482048
DEOPT_IF(tstate->interp->eval_frame);
20492049

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
@@ -891,7 +891,7 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name)
891891
}
892892
case PROPERTY:
893893
{
894-
_PyLoadMethodCache *lm_cache = (_PyLoadMethodCache *)(instr + 1);
894+
_PyLoadPropertyCache *lm_cache = (_PyLoadPropertyCache *)(instr + 1);
895895
assert(Py_TYPE(descr) == &PyProperty_Type);
896896
PyObject *fget = ((_PyPropertyObject *)descr)->prop_get;
897897
if (fget == NULL) {
@@ -917,11 +917,10 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name)
917917
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_OTHER);
918918
goto fail;
919919
}
920-
write_u32(lm_cache->keys_version, version);
921920
assert(type->tp_version_tag != 0);
922921
write_u32(lm_cache->type_version, type->tp_version_tag);
923-
/* borrowed */
924-
write_obj(lm_cache->descr, fget);
922+
write_obj(lm_cache->func, fget); // borrowed
923+
write_u32(lm_cache->func_version, version);
925924
instr->op.code = LOAD_ATTR_PROPERTY;
926925
goto success;
927926
}

0 commit comments

Comments
 (0)