Skip to content

GH-113853: Guarantee forward progress in executors#113854

Merged
markshannon merged 10 commits into
python:mainfrom
faster-cpython:guarantee-forward-progress
Jan 11, 2024
Merged

GH-113853: Guarantee forward progress in executors#113854
markshannon merged 10 commits into
python:mainfrom
faster-cpython:guarantee-forward-progress

Conversation

@markshannon

@markshannon markshannon commented Jan 9, 2024

Copy link
Copy Markdown
Member

Guarantees forward progress in executors by de-specializing the first tier-1 instruction before converting to uops.

Also handles loops a little differently, by comparing the next instruction with the first to find a loop.
Any backwards jump except the very first instruction terminates the trace.

Comment thread Python/bytecodes.c
Comment thread Python/optimizer.c Outdated
Comment thread Python/optimizer.c
Comment thread Python/optimizer.c Outdated
Comment thread Python/optimizer.c Outdated
Comment thread Python/optimizer.c Outdated

@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.

Please also test this locally with tier 2 enabled, since we don't have CI.

Comment thread Python/optimizer.c Outdated
Comment thread Python/optimizer.c Outdated
Comment thread Python/optimizer.c Outdated
Comment thread Python/optimizer.c
Comment thread Python/optimizer.c Outdated
Comment thread Python/optimizer.c Outdated
Comment thread Python/optimizer.c Outdated
@bedevere-app

bedevere-app Bot commented Jan 10, 2024

Copy link
Copy Markdown

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

@gvanrossum

Copy link
Copy Markdown
Member

Please also test this locally with tier 2 enabled, since we don't have CI.

I did, and it's fine.

@markshannon

markshannon commented Jan 10, 2024

Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again.

Thanks for the reviews.

I missed a case that the old code handled: if we start at backwards jump to label top, but end at a different jump to top, the old code would close loop, but this PR would not.
I also think we were handling JUMP_BACKWARD_NO_INTERRUPT incorrectly as it is a different size to JUMP_BACKWARD

I've fixed those issues, but the PR will need to be reviewed again.

@gvanrossum gvanrossum 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.

LGTM, just a suggestion to add another assert.

Comment thread Python/optimizer.c
Comment thread Python/optimizer.c
instr += 2 - (int32_t)oparg;
if (opcode == JUMP_BACKWARD || opcode == JUMP_BACKWARD_NO_INTERRUPT) {
instr += 1 + _PyOpcode_Caches[opcode] - (int32_t)oparg;
initial_instr = instr;

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.

Interesting. This will affect some of the debug output, notably the "Created a trace for ..." message below at line 676 will mention a different byte offset than the "Optimizing ..." above at line 405. I honestly like what you set it to here better, and debug level 4 is excessively verbose, so I don't care, but some bit of me will miss the correspondence. :-)

Comment thread Python/optimizer.c

@gvanrossum gvanrossum 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.

Whoops, no, you need to re-run make regen-cases!

@markshannon
markshannon merged commit 55824d0 into python:main Jan 11, 2024
@markshannon
markshannon deleted the guarantee-forward-progress branch January 11, 2024 18:20
kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants