Skip to content

Inline call frames for CALL_FUNCTION_EX #95126

Open

Description

@Fidget-Spinner

We should apply the call frame inling optimisation to CALL_FUNCTION_EX. Many instances in real world code use *args or **kwargs and they would benefit from this optimisation.

CC @brandtbucher @markshannon

Activity

  1. added
    type-feature
    3.12
    on Jul 22, 2022
  2. added
    performance
    on Jul 22, 2022
  3. brandtbucher commented on Jul 22, 2022

    @brandtbucher
    Member

    Seems like a good idea!

    Are you picturing something similar to CALL, except we unpack *args and **kwargs into new args (instead of stack_pointer) and kwnames (instead of call_shape.kwnames) arrays before the whole _PyEvalFramePushAndInit/initialize_locals dance? I don't think that requires modifying either of those functions, which would be ideal.

  4. markshannon commented on Jul 22, 2022

    @markshannon
    Member

    An alternative approach is to add an extra instruction UNPACK_EX_ARGS to the front of all function code objects, and make sure that all function have stack_size >= 2.
    All vectorcalls and call instructions, other than CALL_FUNCTION_EX would need to jump to instruction 1, instead of 0.

    Then calls with *args and **kwargs (either CALL_FUNCTION_EX or tp_call) can push the *args and **kwargs to the callee's stack and then jump to the start of the caller.
    This is more amenable to specialization, both in the interpreter on the caller's side, and potentially in the compiler on the callee's side.

    Example specializations on the caller's side are CALL_EX_PY_FUNCTION, CALL_EX_METH_VARARGS, etc.

  5. Fidget-Spinner commented on Aug 2, 2022

    @Fidget-Spinner
    MemberAuthor

    @markshannon just checking that we're on the same page:
    UNPACK_EX_ARGS is only supposed to unpack the tuple and dict pushed by CALL_FUNCTION_EX into the callee's stack right?

  6. added
    interpreter-core
    on Nov 27, 2023
  7. added
    3.13
    and removed
    3.12
    on Jan 5, 2024
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

    3.13interpreter-coreperformancetype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions