Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-125837: Rework the instructions for loading constants and returning values.#125878

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@markshannon
Copy link
Member

@markshannonmarkshannon commentedOct 23, 2024
edited by bedevere-appbot
Loading

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

@markshannonmarkshannon changed the titleRework the instructions for loading constants are returning values.GH-125837: Rework the instructions for loading constants are returning values.Oct 23, 2024
@markshannonmarkshannon marked this pull request as draftOctober 23, 2024 13:26
@markshannon
Copy link
MemberAuthor

Performance impactwithout the JIT is in the noise. Nominally 0.2% slower

Performance impactwith the JIT is also in the noise. Nominally 0.2% faster.

Stats shows that almost 90% ofLOAD_CONST are converted toLOAD_CONST_IMMORTAL. There is a 3% increase inEXTENDED_ARG due toLOAD_CONST RETURN_VALUE taking more space thanRETURN_CONST.

My hypothesis is that the slowdown caused by extra dispatching is mostly offset by the more efficientLOAD_CONST in tier 1 and more streamlinedRETURN_VALUEs.
In tier 2 there is no extra overhead for dispatching, which might be why we see a tiny speedup instead of a tiny slowdown.

markshannonand others added2 commitsOctober 24, 2024 09:34
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
@markshannonmarkshannon changed the titleGH-125837: Rework the instructions for loading constants are returning values.GH-125837: Rework the instructions for loading constants and returning values.Oct 24, 2024
@markshannonmarkshannon marked this pull request as ready for reviewOctober 24, 2024 08:53
_PyInterpreterFrame*dying=frame;
frame=tstate->current_frame=dying->previous;
_PyEval_FrameClearAndPop(tstate,dying);
_PyEval_ClearGenFrame(tstate,dying);
Copy link
Member

Choose a reason for hiding this comment

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

Is the only difference betweenRETURN_VALUE_FUNC andRETURN_VALUE_GEN the call to_PyEval_ClearThreadFrame vs_PyEval_ClearGenFrame? Couldn't_PyEval_FrameClearAndPop just switch on whether or notframe->owner == FRAME_OWNED_BY_GENERATOR?

Copy link
MemberAuthor

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)

Copy link
Member

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.

Copy link
MemberAuthor

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.

}

staticbool
all_exits_have_lineno(basicblock*entryblock) {
Copy link
Member

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?

Copy link
MemberAuthor

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.

Copy link
Member

@Eclips4Eclips4Oct 24, 2024
edited
Loading

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, see325c5fe:
‘all_exits_have_lineno’ defined but not used [-Wunused-function]

Copy link
Member

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.

Eclips4 reacted with thumbs up emoji
Copy link
Member

@iritkatrieliritkatriel left a 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.

markshannon reacted with thumbs up emoji
@bedevere-app
Copy link

When you're done making the requested changes, leave the comment:I have made the requested changes; please review again.

@markshannon
Copy link
MemberAuthor

The magic comment is "I have made the requested changes; please review again".
I haven't, but I think I've justified my decisions.
@iritkatriel

@bedevere-app
Copy link

Thanks for making the requested changes!

@iritkatriel: please review the changes made to this pull request.

Copy link
Member

@iritkatrieliritkatriel left a 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.

@markshannon
Copy link
MemberAuthor

I'm closing this for now. We can revisit splitting upRETURN_VALUE when the full refactoring I suggested above is ready.

#125972 splits upLOAD_CONST and removesRETURN_CONST and shows slightly better performance.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@tomasr8tomasr8tomasr8 left review comments

@iritkatrieliritkatrieliritkatriel approved these changes

@Eclips4Eclips4Awaiting requested review from Eclips4Eclips4 is a code owner

@ericsnowcurrentlyericsnowcurrentlyAwaiting requested review from ericsnowcurrentlyericsnowcurrently is a code owner

@Fidget-SpinnerFidget-SpinnerAwaiting requested review from Fidget-SpinnerFidget-Spinner is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@markshannon@iritkatriel@tomasr8@Eclips4

[8]ページ先頭

©2009-2025 Movatter.jp