-
-
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-96421: Introduce cleanup contexts for inlined frames #98795
Conversation
Performance impact is neutral:
|
CC @markshannon. Let me know what you think! |
(Sorry, I thought you were already requested for review, but I forgot that draft PRs don't do that.) |
I don't see how this is simpler. Once you strip out the change note and documentation, the PRs are about the same size. How the cleanup contexts compose? How do you do two things in a cleanup context? |
What I find simpler is that all of the new complexity is limited to a very specific part of
Well, that's a bit unfair. The majority of this PR is the PoC implementations of generator and class inlining, which I thought you might like to see. I've removed those parts since the point's been made, and the PR is downright tiny now. ;) Also, this PR doesn't need as much documentation, since it doesn't break out-of-process debuggers and profilers like the other PR (which I see as a strong point in favor of this approach).
For what? I've demonstrated that inlining generators and class construction is quite straightforward with this approach. To me, it seems general enough for other places where we might want to insert arbitrary cleanup code between frames. I could be missing something, though. What else do we "need" shim functions for?
If by "interpreter" you mean "the eval loop", then maybe. But if by "interpreter" you mean "the entire runtime", then I disagree (strongly).
If we really needed something like this (it sounds like we might not, though), I imagine it could be quite straightforward to do using flags for composable handlers rather than enumerated values, as I've done here. Coming out of the 3.11 prereleases, I feel quite strongly that the last things we need in 3.12 are gratuitous third-party breakage and additional (delicate) rules about how frames should be handled. Why not start simple by leaving shim frames out entirely, then add all of that only when we have a justified need? I'm not 100% opposed to shim frames, I just think that an approach like this one is a better way of solving the same set of problems right now. |
This is intended as an alternative to #96319. I personally find that this is a bit simpler, more scalable, and easier to reason about.
Rather than pushing "shim" frames, give
_PyInterpreterFrame
acleanup
member that tells the interpreter how to handle its two exit paths (the oldexit_unwind
label on error, and the newcleanup
label on success).This proof-of-concept sketches out how inlining generators and class constructions would work under this new scheme by implementing their cleanup code in
exit_unwind
andcleanup
. However, the specializations themselves are still unimplemented.