gh-GH-131798: optimize jit attribute loads on immutable types (#146449)

This commit is contained in:
Kumar Aditya 2026-03-26 15:42:10 +05:30 committed by GitHub
parent b5a27bdcf0
commit fc1f6b176e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View file

@ -367,7 +367,11 @@ lookup_attr(JitOptContext *ctx, _PyBloomFilter *dependencies, _PyUOpInstruction
if (type && PyType_Check(type)) {
PyObject *lookup = _PyType_Lookup(type, name);
if (lookup) {
int opcode = _Py_IsImmortal(lookup) ? immortal : mortal;
int opcode = mortal;
// if the object is immortal or the type is immutable, borrowing is safe
if (_Py_IsImmortal(lookup) || (type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE)) {
opcode = immortal;
}
ADD_OP(opcode, 0, (uintptr_t)lookup);
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)type);
_Py_BloomFilter_Add(dependencies, type);