Skip to content

[mypyc] feat: __mypyc_empty_tuple__ constant #19654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

BobTheBuidler
Copy link
Contributor

@BobTheBuidler BobTheBuidler commented Aug 14, 2025

I realized that any time a user has a kwarg-only call expression like fn(abc=123, ...) in their compiled code, and func is not a native function, a new empty tuple is created every time

This is not really necessary, we can just hold the same empty tuple in memory as a constant and pass it around. It's immutable, and that's already what we're already doing, since tuple() is tuple() but our current method involves more steps.

This should slightly improve the speed of kwarg-only python func calling.

@BobTheBuidler BobTheBuidler marked this pull request as draft August 14, 2025 06:24
@JukkaL
Copy link
Collaborator

JukkaL commented Aug 14, 2025

In 3.13 and later, we could use Py_GetConstant(Py_CONSTANT_EMPTY_TUPLE);. However, having a static variable with the value would be faster, as we'd save at least a function call, and it will work on older Python versions as well, so it's reasonable to cache it in mypyc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants