Skip to content

gh-131798: fold super method lookups in JIT#148231

Merged
kumaraditya303 merged 10 commits intopython:mainfrom
kumaraditya303:jit-super
Apr 9, 2026
Merged

gh-131798: fold super method lookups in JIT#148231
kumaraditya303 merged 10 commits intopython:mainfrom
kumaraditya303:jit-super

Conversation

@kumaraditya303
Copy link
Copy Markdown
Contributor

@kumaraditya303 kumaraditya303 commented Apr 7, 2026

@Fidget-Spinner Fidget-Spinner changed the title gh-131798: cache super method lookups in JIT gh-131798: fold super method lookups in JIT Apr 7, 2026
@Fidget-Spinner
Copy link
Copy Markdown
Member

I see a 10% speedup on richards_super with this PR!

Mean +- std dev: [richards_super_main] 28.8 ms +- 0.5 ms -> [richards_super_fold] 26.1 ms +- 0.5 ms: 1.10x faster

Copy link
Copy Markdown
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one stylistic nit. Thanks!

return sym_new_not_null(ctx);
}
/* Normal case: obj_type must be a subtype of su_type */
if (!PyType_IsSubtype(obj_type, su_type)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: this is not same as subclasscheck/instancecheck, which can call arbitrary code.

@Fidget-Spinner
Copy link
Copy Markdown
Member

Please fix the merge conflicts. LOAD_CONST_UNDER_INLINE_BORROW was removed as it's a duplicate of _INSERT_1_LOAD_CONST_INLIE_BORROW #148235

@kumaraditya303
Copy link
Copy Markdown
Contributor Author

Please fix the merge conflicts.

Fixed.

Copy link
Copy Markdown
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This LGTM.

_Py_BloomFilter_Add(dependencies, su_type);
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)obj_type);
_Py_BloomFilter_Add(dependencies, obj_type);
return sym_new_const_steal(ctx, lookup);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: need steal version because _PySuper_Lookup returns a strong reference, unlike _PyType_Lookup

@Fidget-Spinner
Copy link
Copy Markdown
Member

Please pull in main and regen cases. Thank you.

@markshannon
Copy link
Copy Markdown
Member

Can we have a test for the case where the superclass changes after optimization, to make sure that we de-opt properly?

@kumaraditya303
Copy link
Copy Markdown
Contributor Author

Added test and fixed merge conflicts.

Copy link
Copy Markdown
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test

@kumaraditya303 kumaraditya303 merged commit 458aca9 into python:main Apr 9, 2026
74 checks passed
@kumaraditya303 kumaraditya303 deleted the jit-super branch April 9, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants