Skip to content

gh-131798: JIT: replace _CHECK_METHOD_VERSION with _CHECK_FUNCTION_VERSION_INLINE - #135022

Merged
Fidget-Spinner merged 10 commits into
python:mainfrom
Zheaoli:manjusaka/method-version
Jun 16, 2025
Merged

gh-131798: JIT: replace _CHECK_METHOD_VERSION with _CHECK_FUNCTION_VERSION_INLINE#135022
Fidget-Spinner merged 10 commits into
python:mainfrom
Zheaoli:manjusaka/method-version

Conversation

@Zheaoli

@ZheaoliZheaoli commented Jun 2, 2025

Copy link
Copy Markdown
Contributor

Zheaoli added 3 commits June 2, 2025 20:13
…ION_VERSION_INLINE
Signed-off-by: Manjusaka <me@manjusaka.me>
Signed-off-by: Manjusaka <me@manjusaka.me>
Zheaoli added 2 commits June 2, 2025 20:15
Signed-off-by: Manjusaka <me@manjusaka.me>
Signed-off-by: Manjusaka <me@manjusaka.me>

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

Very cool, thanks! A few suggestions:

Comment threadPython/optimizer_bytecodes.c Outdated
Comment on lines +2239 to +2245
class TestObject:
def test(self, *args, **kwargs):
return args[0]

test_object = TestObject()
test_bound_method = TestObject.test.__get__(test_object)

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.

Can you move this into test_method_guards_removed_or_reduced? global_identity needs to be at module scope for other reasons that don't apply here.

Also, I think it can be simplified to something like:

classTestObject:
deftest(self, arg):
returnargtest_bound_method=TestObject().test

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

If I'm correct, TestObject().test will just generate _CHECK_FUNCTION_VERSION code, It's a normal function.

Reference the test code here

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Can you move this into test_method_guards_removed_or_reduced? global_identity needs to be at module scope for other reasons that don't apply here.

BTW, if I push the test object into the test_method_guards_removed_or_reduced. I think the method will not be treated by a const. So we the _CHECK_FUNCTION_VERSION_INLINE is not exist in final opcode.

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.

@Zheaoli is right here. Can you please move this back to global scope? It seems tests are failing as the global method is not being promoted to a constant.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Can you please move this back to global scope? It seems tests are failing as the global method is not being promoted to a constant.

Sure

Comment threadLib/test/test_capi/test_opt.py Outdated
Zheaoliand others added 4 commits June 7, 2025 08:16
…e-131798.JQRFvR.rst
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
Signed-off-by: Manjusaka <me@manjusaka.me>
Signed-off-by: Manjusaka <me@manjusaka.me>
Signed-off-by: Manjusaka <me@manjusaka.me>

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

Sorry for forgetting to review this. This looks like a good optimization --- _CHECK_FUNCTION_VERSION_INLINE has one fewer memory indirection than _CHECK_METHOD_VERSION

@Zheaoli

Copy link
Copy Markdown
ContributorAuthor

@brandtbucher I update some idea about the test, PTAL when you got time.

Signed-off-by: Manjusaka <me@manjusaka.me>
@Fidget-Spinner
Fidget-Spinner merged commit 667a86e into python:mainJun 16, 2025
@Zheaoli
Zheaoli deleted the manjusaka/method-version branch June 16, 2025 05:58
lkollar pushed a commit to lkollar/cpython that referenced this pull request Jun 19, 2025
…ION_VERSION_INLINE (pythonGH-135022)
Signed-off-by: Manjusaka <me@manjusaka.me>
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
…ION_VERSION_INLINE (pythonGH-135022)
Signed-off-by: Manjusaka <me@manjusaka.me>
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
…ION_VERSION_INLINE (pythonGH-135022)
Signed-off-by: Manjusaka <me@manjusaka.me>
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
…ION_VERSION_INLINE (pythonGH-135022)
Signed-off-by: Manjusaka <me@manjusaka.me>
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@Zheaoli@Fidget-Spinner@brandtbucher@ZeroIntensity