-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
gh-128563: A new tail-calling interpreter #128718
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good in general.
Quite a few code quality issues, but nothing difficult to fix.
Instead of the preamble
#ifdef Py_TAIL_CALL_INTERP
int opcode = next_instr->op.code;
(void)(opcode);
#endif /* Py_TAIL_CALL_INTERP */
#ifdef Py_TAIL_CALL_INTERP
_Py_CODEUNIT* const this_instr = next_instr;
(void)this_instr;
#endif /* Py_TAIL_CALL_INTERP */
frame->instr_ptr = next_instr;we could leave it to the C compiler to determine whether this_instr or opcode are used and take advantage of the fact that we know statically what the opcode is.
Then we just need to emit this:
_Py_CODEUNIT* const this_instr = next_instr;
frame->instr_ptr = this_instr;
int opcode = {OPCODE};
(void)(opcode);Which should be a tad quicker and easier to read.
|
When you're done making the requested changes, leave the comment: |
|
I have made the requested changes; please review again. |
|
Thanks for making the requested changes! @markshannon: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
The dispatching mechanism is now distinct from the actions, even in the generated code, which is nice.
Just one quibble, but that can be done in another PR if you want.
Do we have up to date performance numbers?
No need to do that before merging, but it would be good to have the performance impact on record.
Lib/test/test_generated_cases.py
Outdated
| @@ -304,6 +304,10 @@ def test_inst_no_args(self): | |||
| """ | |||
| output = """ | |||
| TARGET(OP) { | |||
| int opcode = OP; | |||
| (void)(opcode); | |||
| _Py_CODEUNIT* const this_instr = next_instr; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generated sequence
_Py_CODEUNIT* const this_instr = next_instr;
(void)this_instr;
frame->instr_ptr = next_instr;would be neater as:
_Py_CODEUNIT* const this_instr = next_instr;
frame->instr_ptr = this_instr;
No, but the benchmarking infra can't benchmark this anyways. Because it's opt-in. @mdboom perhaps we could add the configure option now? |
|
@markshannon we can't do the |
|
Great work on this, @Fidget-Spinner! |
Co-authored-by: Garrett Gu <garrettgu777@gmail.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>


Features:
Preliminary benchmark results here https://github.com/faster-cpython/benchmarking-public/tree/main/results/bm-20250107-3.14.0a3+-f1d3190-CLANG
TLDR (all results are pyperformance, clang-19, with PGO + ThinLTO unless stated otherwise):
More recent benchmark results:
https://github.com/faster-cpython/benchmarking-public/tree/main/results/bm-20250116-3.14.0a4+-df5d01c-CLANG
This initial implementation focuses on correctness. There's still room to improve performance even further. I've detailed performance plans in the original issue.
Changset:
configure.acto auto-detect when we can do this.opcodein the call arguments because it might be modified by instrumented instructions.Credits also to Brandt and Savannah for the JIT workflow file.