-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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-125837: Rework the instructions for loading constants and returning values. #125878
GH-125837: Rework the instructions for loading constants and returning values. #125878
Conversation
Performance impact without the JIT is in the noise. Nominally 0.2% slower Performance impact with the JIT is also in the noise. Nominally 0.2% faster. Stats shows that almost 90% of My hypothesis is that the slowdown caused by extra dispatching is mostly offset by the more efficient |
Co-authored-by: Tomas R. <[email protected]>
@@ -993,7 +1023,7 @@ dummy_func( | |||
// GH-99729: We need to unlink the frame *before* clearing it: | |||
_PyInterpreterFrame *dying = frame; | |||
frame = tstate->current_frame = dying->previous; | |||
_PyEval_FrameClearAndPop(tstate, dying); | |||
_PyEval_ClearGenFrame(tstate, dying); |
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.
Is the only difference between RETURN_VALUE_FUNC
and RETURN_VALUE_GEN
the call to _PyEval_ClearThreadFrame
vs _PyEval_ClearGenFrame
? Couldn't _PyEval_FrameClearAndPop
just switch on whether or not frame->owner == FRAME_OWNED_BY_GENERATOR
?
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.
That's exact what it used to do.
We generally want to make decisions at compile time if we can.
It's the second bullet in #125837 (comment)
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.
We generally want to make decisions at compile time if we can.
We also made some efforts to reduce the number of bytecodes and the size of the eval loop implementation.
And copy-pasting 20 lines of code to change one is... controversial.
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.
And copy-pasting 20 lines of code to change one is... controversial.
It's 16 lines, but I see your point.
Doing this gives more flexibility to refactor and optimize the two return paths separately.
Both _PyEval_ClearGenFrame
and _PyEval_ClearThreadFrame
call _PyFrame_ClearExceptCode()
but have to do
different things around that call.
For example, we could end up with something like this:
macro(RETURN_VALUE_FUNC) = _CLEAR_FRAME + _POP_THREAD_FRAME + _RETURN_VALUE;
macro(RETURN_VALUE_GEN) = _GEN_POP_EXC_STATE + _CLEAR_FRAME + _RETURN_VALUE;
but not in this PR.
@@ -515,22 +515,6 @@ no_redundant_jumps(cfg_builder *g) { | |||
} | |||
return true; | |||
} | |||
|
|||
static bool | |||
all_exits_have_lineno(basicblock *entryblock) { |
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.
Could you comment out rather than delete?
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.
I'd rather delete it, otherwise it just rots.
We do have version control, if you need it back.
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.
Could you comment out rather than delete?
If it doesn't get deleted, compiler may raise warnings, see 325c5fe:
‘all_exits_have_lineno’ defined but not used [-Wunused-function]
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.
If it doesn't get deleted, compiler may raise warnings
But not if it's commented out.
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.
dis doc needs updating.
When you're done making the requested changes, leave the comment: |
The magic comment is "I have made the requested changes; please review again". |
Thanks for making the requested changes! @iritkatriel: 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.
I have reservation about introducing yet more code duplication, but I understand you are adamant this is a good idea.
I'm closing this for now. We can revisit splitting up #125972 splits up |
Adds:
RETURN_VALUE_FUNC
RETURN_VALUE_GEN
INSTRUMENTED_RETURN_VALUE_FUNC
INSTRUMENTED_RETURN_VALUE_GEN
LOAD_CONST_IMMORTAL
Removes:
RETURN_VALUE
RETURN_CONST
INSTRUMENTED_RETURN_VALUE
INSTRUMENTED_RETURN_CONST
RETURN_VALUE
andRETURN_CONST
#125837