GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-131798: Skip `self`/`NULL` checks for some known non-methods by brandtbucher · Pull Request #132278 · python/cpython

Conversation

@brandtbucher

@brandtbucher brandtbucher commented Apr 8, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

CALL_TYPE_1, CALL_STR_1, CALL_TUPLE_1, CALL_LEN, and CALL_ISINSTANCE will never call a method descriptor, which means that we can just assert that self_or_null is NULL instead of checking and "adjusting" the arguments each time.

CALL_BUILTIN_CLASS should never call a method descriptor, but I'm not sure that we can gurantee it. So I've just made this a DEOPT_IF instead.

  • Issue: Better uop coverage in the JIT optimizer #131798

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
brandtbucher added 2 commits April 7, 2025 20:35
@brandtbucher
Don't check whethed non-methods are methods
fe5b174
@brandtbucher
blurb add
873829d
@brandtbucher brandtbucher added performance Performance or resource usage interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Apr 8, 2025
@brandtbucher brandtbucher self-assigned this Apr 8, 2025
@brandtbucher
brandtbucher requested a review from markshannon as a code owner April 8, 2025 16:08
@bedevere-app bedevere-app Bot added the awaiting core review label Apr 8, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Apr 8, 2025
Better uop coverage in the JIT optimizer #131798
Open
@markshannon

markshannon commented Apr 8, 2025

Copy link
Copy Markdown
Member

What about this:

def call_x(a, b):
    return a.x(b)
class C: pass
c = C()
c.x = type
call_x(c, 1); call_x(c, 1)
f = types.MethodType(type, 3)
class D:
    x = f
d = D()
call_x(d, "string")
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher

brandtbucher commented Apr 8, 2025

Copy link
Copy Markdown
Member Author

I'll try, but I'm pretty sure those are fine, since LOAD_ATTR only performs the "unwrapping" optimization for method descriptors (type, str, tuple, len, isisinstance, and types.MethodType aren't).

At any rate, I'll add a test.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher
Add tests for weird method patterns
ec5c674
@brandtbucher

brandtbucher commented Apr 8, 2025

Copy link
Copy Markdown
Member Author

@markshannon, I went ahead and added a bunch of tests for weird method patterns like that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon

markshannon commented Apr 9, 2025

Copy link
Copy Markdown
Member

I'm still reluctant to make this change, as it makes the behavior of individual instructions depend on implicit context.
For example, this function:

def f(x, a, b):
     return x(a, b)

currently compiles as

  1           RESUME                   0

  2           LOAD_FAST_BORROW         0 (x)
              PUSH_NULL
              LOAD_FAST_BORROW_LOAD_FAST_BORROW 18 (a, b)
              CALL                     2
              RETURN_VALUE

but it could be correctly compiled as:

  1           RESUME                   0

  2           LOAD_FAST_BORROW         0 (x)
              LOAD_FAST_BORROW_LOAD_FAST_BORROW 18 (a, b)
              CALL                     1
              RETURN_VALUE

which would not work with this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon

markshannon commented Apr 9, 2025

Copy link
Copy Markdown
Member

IIRC, we use do just something like that. When compiling m.f(...) if m was defined by an import we would use LOAD_ATTR instead of LOAD_METHOD, so that m.f(a, b) would compile to the then equivalent of CALL 1

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher brandtbucher closed this May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@brandtbucher brandtbucher

Labels

awaiting core review interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@brandtbucher @markshannon
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.