classification
Title: Perform "peephole" optimization directly on control-flow graph.
Type: performance Stage: resolved
Components: Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Mark.Shannon Nosy List: Mark.Shannon, rhettinger, tim.peters, vstinner
Priority: normal Keywords: patch

Created on 2020-07-17 10:27 by Mark.Shannon, last changed 2020-07-30 09:04 by Mark.Shannon. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 21517 merged Mark.Shannon, 2020-07-17 10:38
Messages (3)
msg373811 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2020-07-17 10:27
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.
msg373848 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-07-17 19:00
+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.
msg374606 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2020-07-30 09:03
New changeset 6e8128f02e1d36e38e5866f9dc36e051caa47bc9 by Mark Shannon in branch 'master':
bpo-41323: Perform 'peephole' optimizations directly on the CFG. (GH-21517)
https://github.com/python/cpython/commit/6e8128f02e1d36e38e5866f9dc36e051caa47bc9
History
Date User Action Args
2020-07-30 09:04:04Mark.Shannonsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-07-30 09:03:27Mark.Shannonsetmessages: + msg374606
2020-07-19 06:13:34rhettingersetnosy: + tim.peters
2020-07-17 19:00:00rhettingersetnosy: + rhettinger
messages: + msg373848
2020-07-17 18:45:38brett.cannonsetnosy: + vstinner
2020-07-17 10:38:08Mark.Shannonsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request20653
2020-07-17 10:27:02Mark.Shannoncreate