Skip to content

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

Description

@markshannon
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 = []

    Activity

    1. markshannon commented on Jul 17, 2020

      @markshannon
      MemberAuthor

      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.

    2. self-assigned this
      on Jul 17, 2020
    3. self-assigned this
      on Jul 17, 2020
    4. rhettinger commented on Jul 17, 2020

      @rhettinger
      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.

    5. markshannon commented on Jul 30, 2020

      @markshannon
      MemberAuthor

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

    6. methane commented on Apr 16, 2021

      @methane
      Member

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

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    performancePerformance or resource usage

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions