Skip to content

gh-131798: JIT: Optimize _CALL_LEN when the length is known - #135260

Merged
tomasr8 merged 4 commits into
python:mainfrom
tomasr8:jit-call-len-known-length
Jun 20, 2025
Merged

tomasr8 merged 4 commits into
python:mainfrom
tomasr8:jit-call-len-known-length

Conversation

@tomasr8

@tomasr8 tomasr8 commented Jun 8, 2025 •

Copy link
Copy Markdown
Member

This uses the same principle as #135194 to completely remove _CALL_LEN when the length is known.

I don't know how common it is to actually know the length exactly so please let me know if this is not worth it, but given that _CALL_LEN is the most common builtin call, it felt worth to optimize this case.

Comment on lines +1195 to +1207
int tuple_length = sym_tuple_length(arg);
if (tuple_length >= 0) {
PyObject *temp = PyLong_FromLong(tuple_length);
if (temp == NULL) {
goto error;
}
if (_Py_IsImmortal(temp)) {
REPLACE_OP(this_instr, _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW,
0, (uintptr_t)temp);
}
res = sym_new_const(ctx, temp);
Py_DECREF(temp);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is basically copied from the recent _GET_LEN optimization

Comment thread Lib/test/test_capi/test_opt.py Resolved
@tomasr8
tomasr8 requested a review from brandtbucher June 8, 2025 15:44

@brandtbucher brandtbucher left a comment

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.

Looks good! I'll leave this for you to merge yourself. ;)

@tomasr8

tomasr8 commented Jun 20, 2025

Copy link
Copy Markdown
Member Author

I'm planning to merge this once the tests pass :)

@tomasr8
tomasr8 merged commit 61532b4 into python:main Jun 20, 2025
@tomasr8
tomasr8 deleted the jit-call-len-known-length branch June 20, 2025 16:21
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants