Skip to content

gh-100712: make it possible to disable specialization (for debugging) #100713

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 6 commits into from
Jan 19, 2023

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Jan 3, 2023

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Yup.

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

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

Nice addition. I've left some minor comments.

I wonder if the changes in ceval.c would be cleaner if we just changed the "ADAPTIVE_COUNTER" macro definitions when ENABLE_SPECIALIZATION is zero (instead of sprinkling these #ifs everywhere). Might be about the same level of complexity, though.

@@ -304,6 +304,7 @@ dummy_func(
};

inst(BINARY_SUBSCR, (unused/4, container, sub -- res)) {
#if ENABLE_SPECIALIZATION
Copy link
Member

Choose a reason for hiding this comment

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

Style nit:

Typically, we unindent #if/#else/#endif one level for easier readability. I find this a bit easier to parse:

Suggested change
#if ENABLE_SPECIALIZATION
#if ENABLE_SPECIALIZATION

Copy link
Member

Choose a reason for hiding this comment

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

I know that's traditional, but honestly I'm not too happy with that convention and I find it less readable that what Irit proposes here. Also, she tried outdenting it in an early regmachine branch and the generated code was indentded weirdly.

@@ -276,6 +276,7 @@ static int compare_masks[] = {
void
_PyCode_Quicken(PyCodeObject *code)
{
#if ENABLE_SPECIALIZATION
Copy link
Member

Choose a reason for hiding this comment

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

I think this change isn't needed unless you also want to disable superinstructions. That seems like something separate, and less useful, than what you're proposing here.

Copy link
Member

Choose a reason for hiding this comment

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

IIRC it had something to do with making the interpreter easier to debug when nothing works. The more you can rule out the less code you have left to debug.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if the changes in ceval.c would be cleaner if we just changed the "ADAPTIVE_COUNTER" macro definitions when ENABLE_SPECIALIZATION is zero (instead of sprinkling these #ifs everywhere). Might be about the same level of complexity, though.

Possibly. But if we want to exclude this code from compilation we would need to rewrite ADAPTIVE_COUNTER_IS_ZERO so that it's not in an if condition.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this change isn't needed unless you also want to disable superinstructions. That seems like something separate, and less useful, than what you're proposing here.

We could have a separate flat ENABLE_SUPERINSTRUCTIONS for that. We could have toggles for different kinds of optimisations, with a global one to turn them all off for debugging (the individual ones can be used to assess the performance gain of the parts, and to better document what is what):

ENABLE_BYTECODE_OPTIMIZATIONS = True
ENABLE_SPECIALIZATION = ENABLE_BYTECODE_OPTIMIZATIONS and True
ENABLE_SUPERINSTRUCTIONS = ENABLE_BYTECODE_OPTIMIZATIONS and True
ENABLE_PEEPHOLER = ENABLE_BYTECODE_OPTIMIZATIONS and True
...

Copy link
Member

Choose a reason for hiding this comment

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

This is a feature for extreme debugging. I'd keep it as simple as possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll merge then. We can iterate on this.

@iritkatriel iritkatriel merged commit e9ccfe4 into python:main Jan 19, 2023
@iritkatriel iritkatriel deleted the disable_specialization branch July 25, 2023 18:08
@iritkatriel iritkatriel restored the disable_specialization branch July 25, 2023 18:08
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.

Make it possible to disable specialization (for debugging).
4 participants