Skip to content

[3.11] GH-93354: Use exponential backoff to avoid excessive specialization attempts (GH-93355) - #93379

Merged
ambv merged 4 commits into
3.11from
backport-eb618d5-3.11
Jun 30, 2022
Merged

ambv merged 4 commits into
3.11from
backport-eb618d5-3.11

Conversation

@markshannon

@markshannon markshannon commented May 31, 2022 •

Copy link
Copy Markdown
Member

Backport of #93355

This doesn't fix any obvious bugs in 3.11, but it is a preventative fix.

Specialization of some instructions can be quite expensive (relative to the cost of executing the instruction), so we want to avoid excessive numbers of failed specializations for corner cases that we might not yet be aware of.

@pablogsal

…ation attempts. (GH-93355)

(cherry picked from commit eb618d5)

Co-authored-by: Mark Shannon <[email protected]>
@pablogsal

Copy link
Copy Markdown
Member

Seems there is a bunch of compiler warnings (check the "Files" tab in this PR). Also, there is a lot of code here and I am not sure I feel very confident merging this so I suppose it depends on how bd is the regression we are fixing. Could you elaborate with some benchmarks on the cases this is fixing (I know there is an explanation on the issue, but I want some discussion here specific for 3.11).

Also, if we decided to go with this, we are going to need at least 2 other core devs to review and approve this change.

@markshannon

Copy link
Copy Markdown
Member Author

Seems there is a bunch of compiler warnings

Cherry picker messed up the merge. I'll fix that.

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

This LGTM.

Re: what Pablo said. IMO the risk of introducing bugs with this change is low. At worst we degrade performance a little. I don't see how this could introduce anything majorly breaking.

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

Wait, I think we need to apply the changes to these lines too:

cpython/Python/ceval.c

Lines 5605 to 5613 in 6b33000

miss:
{
STAT_INC(opcode, miss);
opcode = _PyOpcode_Deopt[opcode];
STAT_INC(opcode, miss);
/* The counter is always the first cache entry: */
_Py_CODEUNIT *counter = (_Py_CODEUNIT *)next_instr;
*counter -= 1;
if (*counter == 0) {

I suddenly noticed on my main branch that it now takes 53 misses to deopt an instruction. That seems high.

@bedevere-bot

Copy link
Copy Markdown

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

@Fidget-Spinner

Copy link
Copy Markdown
Member

I suddenly noticed on my main branch that it now takes 53 misses to deopt an instruction. That seems high.

I opened #93860 to fix that.

@markshannon

Copy link
Copy Markdown
Member Author

There is no change. 53 is the same as before. This PR changes the number of executions to the next specialization attempt, not the number of misses before deoptimization.

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

My bad, that was confusion on my part. Once again this LGTM.

@pablogsal

pablogsal commented Jun 23, 2022 •

Copy link
Copy Markdown
Member

@markshannon Can you please rebase this so I can land it to the new beta?

We are still missing another core dev approval

@ambv

ambv commented Jun 30, 2022

Copy link
Copy Markdown
Contributor

I went through the PR, compared it with main, built a pydebug and a macOS framework release Python with this PR, ran regrtest on both. Looks good to me.

@ambv
ambv merged commit 113b309 into 3.11 Jun 30, 2022
@ambv
ambv deleted the backport-eb618d5-3.11 branch June 30, 2022 21:03
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.

5 participants