Visitar URL original
Near zero-cost super().meth() calls via adaptive superinstructions · Issue #90722 · python/cpython · GitHub
Skip to content

Near zero-cost super().meth() calls via adaptive superinstructions #90722

Description

@Fidget-Spinner
BPO 46564
Nosy @markshannon, @corona10, @Fidget-Spinner, @kumaraditya303
PRs
  • bpo-46564: Optimize super().meth() calls via adaptive superinstructions #30992
  • bpo-46564: do not create frame object for super object #31002
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/Fidget-Spinner'
    closed_at = None
    created_at = <Date 2022-01-28.16:36:58.296>
    labels = ['interpreter-core', '3.11', 'performance']
    title = 'Near zero-cost super().meth() calls via adaptive superinstructions'
    updated_at = <Date 2022-03-29.17:49:41.787>
    user = 'https://github.com/Fidget-Spinner'

    bugs.python.org fields:

    activity = <Date 2022-03-29.17:49:41.787>
    actor = 'corona10'
    assignee = 'kj'
    closed = False
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2022-01-28.16:36:58.296>
    creator = 'kj'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46564
    keywords = ['patch']
    message_count = 6.0
    messages = ['412005', '412050', '412051', '412052', '412055', '412259']
    nosy_count = 4.0
    nosy_names = ['Mark.Shannon', 'corona10', 'kj', 'kumaraditya']
    pr_nums = ['30992', '31002']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue46564'
    versions = ['Python 3.11']

    Activity

    1. Fidget-Spinner commented on Jan 28, 2022

      @Fidget-Spinner
      MemberAuthor

      super().meth() is expensive. I propose to optimize 3 parts of this:

      1. Avoid creating a temporary super() proxy object.
      2. Avoid creating a bound method.
      3. Avoid method lookup in super MRO using the inline cache.

      Credit for 1. and 2. doesn't belong to me. Those were inspired by the excellent work done in bpo-43563.

      I'll do this by combining the adjacent CALL (super) and LOAD_METHOD instructions into CALL_NO_KW_SUPER__LOAD_METHOD. Using the specializer means:

      • We don't touch any compiler code.
      • This custom instruction isn't revealed to the user
      • I can make use of the 5 cache entries shared by both CALL_ADAPTIVE and LOAD_METHOD_ADAPTIVE.

      The final 2-argument super(type, obj).meth() form will have almost no overhead over a corresponding self.meth() call in the current implementation.

      Please see faster-cpython/ideas#242 and faster-cpython/ideas#239 for more info.

    2. kumaraditya303 commented on Jan 29, 2022

      @kumaraditya303
      Contributor

      I was reading typeobject.c and noticed that creating a super object currently requires creating a frame object which is created lazily and is slow and it would work with the InterpreterFrame as well so I created a PR for this optimization and now it does not requires creating frame objects.

    3. Fidget-Spinner commented on Jan 29, 2022

      @Fidget-Spinner
      MemberAuthor

      @Kumar, my PR already has your changes.

    4. kumaraditya303 commented on Jan 29, 2022

      @kumaraditya303
      Contributor

      Oh, I didn't see your PR and commented as it was not mentioned in this bpo. Would you like to split the PR or continue with yours, either way is fine?

    5. Fidget-Spinner commented on Jan 29, 2022

      @Fidget-Spinner
      MemberAuthor

      Oh, I didn't see your PR and commented as it was not mentioned in this bpo.

      No problem. In the future please check the "Pull Requests" section on the issue. People don't always say "I created a PR at xxx". Often times we just link the PR into the issue itself.

      Keep your PR around in case mine gets rejected, then we can take just the good parts. If mine's accepted, we can close yours.

    6. Fidget-Spinner commented on Feb 1, 2022

      @Fidget-Spinner
      MemberAuthor

      New changeset b9ebde8 by Kumar Aditya in branch 'main':
      bpo-46564: do not create frame object for super object (GH-31002)
      b9ebde8

    7. transferred this issue fromon Apr 10, 2022
    8. added
      3.12only security fixes
      and removed
      3.11only security fixes
      on Sep 12, 2022
    9. Fidget-Spinner commented on Apr 27, 2023

      @Fidget-Spinner
      MemberAuthor

      Superseded by #87729.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Labels

    3.12only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usage

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions