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

Perform "peephole" optimization directly on control-flow graph. #85495

Closed
markshannon opened this issue Jul 17, 2020 · 4 comments
Closed

Perform "peephole" optimization directly on control-flow graph. #85495

markshannon opened this issue Jul 17, 2020 · 4 comments
Assignees
Labels
performance Performance or resource usage

Comments

@markshannon
Copy link
Member

BPO 41323
Nosy @tim-one, @rhettinger, @vstinner, @methane, @markshannon
PRs
  • bpo-41323: Perform 'peephole' optimizations directly on the CFG. #21517
  • bpo-41323: compiler: Reuse tuple in constant tuple folding #25419
  • 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/markshannon'
    closed_at = <Date 2020-07-30.09:04:04.543>
    created_at = <Date 2020-07-17.10:27:02.814>
    labels = ['performance']
    title = 'Perform "peephole" optimization directly on control-flow graph.'
    updated_at = <Date 2021-04-16.05:01:32.524>
    user = 'https://github.com/markshannon'

    bugs.python.org fields:

    activity = <Date 2021-04-16.05:01:32.524>
    actor = 'methane'
    assignee = 'Mark.Shannon'
    closed = True
    closed_date = <Date 2020-07-30.09:04:04.543>
    closer = 'Mark.Shannon'
    components = []
    creation = <Date 2020-07-17.10:27:02.814>
    creator = 'Mark.Shannon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41323
    keywords = ['patch']
    message_count = 4.0
    messages = ['373811', '373848', '374606', '391165']
    nosy_count = 5.0
    nosy_names = ['tim.peters', 'rhettinger', 'vstinner', 'methane', 'Mark.Shannon']
    pr_nums = ['21517', '25419']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue41323'
    versions = []

    @markshannon
    Copy link
    Member Author

    Currently we perform various bytecode improvements as a pass on the code objects after generating the code object.

    This requires parsing the bytecode to find instructions, recreating the CFG, and rewriting the line number table.

    If we perform the optimizations directly on the CFG we can avoid all that additional work.

    This would save hundreds of lines of code and avoid coupling the optimization to the line number table format.

    @markshannon markshannon self-assigned this Jul 17, 2020
    @markshannon markshannon added the performance Performance or resource usage label Jul 17, 2020
    @markshannon markshannon self-assigned this Jul 17, 2020
    @markshannon markshannon added the performance Performance or resource usage label Jul 17, 2020
    @rhettinger
    Copy link
    Contributor

    +1 This looks like a nice improvement. I've long wanted the optimizations to be moved upstream.

    At the time the peephole logic was first written, operating directly on the code object was the only option that kept optimizations separate from the core compiler logic. But disassembling and reassembling bytecode was always awkward — it is nice to no longer have to do so.

    @markshannon
    Copy link
    Member Author

    New changeset 6e8128f by Mark Shannon in branch 'master':
    bpo-41323: Perform 'peephole' optimizations directly on the CFG. (GH-21517)
    6e8128f

    @methane
    Copy link
    Member

    methane commented Apr 16, 2021

    New changeset 8a232c7 by Inada Naoki in branch 'master':
    bpo-41323: compiler: Reuse tuple in constant tuple folding (GH-25419)
    8a232c7

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    performance Performance or resource usage
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants