Skip to content

gh-93143: Avoid NULL check in LOAD_FAST based on analysis in the compiler #93144

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

Merged
merged 29 commits into from
May 31, 2022

Conversation

sweeneyde
Copy link
Member

@sweeneyde sweeneyde commented May 23, 2022

@sweeneyde
Copy link
Member Author

I collected stats for python -m test, but these are the important execution counts:

Name Count Self Cumulative Miss ratio
LOAD_FAST 737953927 14.2% 14.2%
(...)
LOAD_FAST_CHECK 1470405 0.0% 99.6%
(...)

In other words, 99.80% of all LOAD_FAST can be converted.

@bedevere-bot
Copy link

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

@sweeneyde
Copy link
Member Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

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

@ericsnowcurrently ericsnowcurrently removed their request for review May 24, 2022 19:49
@ericsnowcurrently
Copy link
Member

I'll trust @markshannon and @brandtbucher to review this further. 😄

@markshannon
Copy link
Member

Performance looks good, if a bit noisy

@markshannon
Copy link
Member

Code changes look good to me.
@iritkatriel care to take a look, as you've been working on the compiler lately?

Python/compile.c Outdated
PyObject *index = PyDict_GetItem(c->u->u_varnames, param);
assert(index != NULL);
assert(PyLong_CheckExact(index));
long l_index = PyLong_AsLong(index);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't l_index == i always?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, it looks like it. The assertion passed, so I removed that code.

Looking at symtable.c, It looks like every VISIT(st, arguments, ...); is immediately preceded by a symtable_enter_block(...), so parameters should be guaranteed to be at the lowest indices.

assert(instr->i_opcode != STORE_FAST__LOAD_FAST);
assert(instr->i_opcode != LOAD_CONST__LOAD_FAST);
assert(instr->i_opcode != STORE_FAST__STORE_FAST);
assert(instr->i_opcode != LOAD_FAST__LOAD_CONST);
Copy link
Member

Choose a reason for hiding this comment

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

I recently added IS_ASSEMBLER_OPCODE to contain a list of opcodes that we don't emit in code gen stage, but rather the assembler can use them to replace other opcodes. Would the superinstruction opcodes fit in that list?

Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I know, super-instructions are only ever created at quickening time, not compile-time/assembly-time, so I'm not sure it's right to call them assembler opcodes. I think I remember someone hinting at that potentially changing so that all code is quickened by default? If this becomes the case then maybe it makes sense to add an IS_SUPERINSTRUCTION() macro?

@sweeneyde sweeneyde added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 31, 2022
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @sweeneyde for commit d569c5f 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 31, 2022
@sweeneyde sweeneyde merged commit f425f3b into python:main May 31, 2022
@sweeneyde sweeneyde deleted the known branch May 31, 2022 20:32
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