Skip to content

JIT: _INIT_CALL_BOUND_METHOD loses too much information/_RECORD_BOUND_METHOD not implemented #148438

Closed

Description

@Fidget-Spinner

Feature or enhancement

Proposal:

It seems _RECORD_BOUND_METHOD exists in bytecodes.c but is not implemented in optimizer_bytecodes.c This means _INIT_CALL_BOUND_METHOD fails to get probable method and does not continue optimizing the trace.

The problem with not doing this is that the _PUSH_FRAME at the call site for the bound method decides to hit bottom because it sees no code object :(. So any trace with a call to a bound method does not get optimized after the call. This is pretty bad...

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. Fidget-Spinner commented on Apr 12, 2026

    @Fidget-Spinner
    MemberAuthor

    @NekoAsakura would you like to take this on please (also, I know I've been giving you a lot of issues recently, but it's only because you're good :).

    The idea is to change _RECORD_BOUND_METHOD to record the actual bound callable:

            tier2 op(_RECORD_BOUND_METHOD, (callable, self, args[oparg] -- callable, self, args[oparg])) {
                PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
                if (Py_TYPE(callable_o) == &PyMethod_Type) {
                    RECORD_VALUE(callable_o);
                }
            }
    

    In _CHECK_METHOD_VERSION, we promote the value to a constant one if func_version matches (we need to leave the guard in though). We promote it using sym_set_const after getting the sym_get_probable_value.

    Finally, _EXPAND_METHOD will expand the method same as what it does in bytecodes.c, and sym_new_const the callable and self.

    There should be a test that tests if we manage to optimize through a call to a bound method (e.g. A.b()). The trace inside the b should be optimized, and the optimizer should not stop midway.

  2. NekoAsakura commented on Apr 12, 2026

    @NekoAsakura
    Member

    NP! Keep them coming. Having a clear direction is much better than fumbling about, and I'm properly enjoying getting to know JIT through these PRs.

  3. added 6 commits that reference this issue on Apr 12, 2026
  4. added 2 commits that reference this issue on Apr 12, 2026
  5. added a commit that references this issue on Apr 13, 2026
  6. added a commit that references this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-JITtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions