Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Fidget-Spinner opened this issue Jan 28, 2022 · 7 comments
Closed
Assignees
Labels
3.12 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Comments

@Fidget-Spinner
Copy link
Member

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']

    @Fidget-Spinner
    Copy link
    Member Author

    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.

    @Fidget-Spinner Fidget-Spinner added the 3.11 only security fixes label Jan 28, 2022
    @Fidget-Spinner Fidget-Spinner self-assigned this Jan 28, 2022
    @Fidget-Spinner Fidget-Spinner added interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage labels Jan 28, 2022
    @kumaraditya303
    Copy link
    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.

    @Fidget-Spinner
    Copy link
    Member Author

    @Kumar, my PR already has your changes.

    @kumaraditya303
    Copy link
    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?

    @Fidget-Spinner
    Copy link
    Member Author

    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.

    @Fidget-Spinner
    Copy link
    Member Author

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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @iritkatriel iritkatriel added 3.12 bugs and security fixes and removed 3.11 only security fixes labels Sep 12, 2022
    @Fidget-Spinner
    Copy link
    Member Author

    Superseded by #87729.

    @Fidget-Spinner Fidget-Spinner closed this as not planned Won't fix, can't repro, duplicate, stale Apr 27, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.12 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants