This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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, methane, rhettinger, tim.peters, vstinner
Priority: normal Keywords: patch

Created on 2020-07-17 10:27 by Mark.Shannon, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 21517 merged Mark.Shannon, 2020-07-17 10:38
PR 25419 merged methane, 2021-04-15 01:17
Messages (4)
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
msg391165 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2021-04-16 05:01
New changeset 8a232c7b17a2e41ae14d8bb7937ddfea69301dce by Inada Naoki in branch 'master':
bpo-41323: compiler: Reuse tuple in constant tuple folding (GH-25419)
https://github.com/python/cpython/commit/8a232c7b17a2e41ae14d8bb7937ddfea69301dce
History
Date User Action Args
2022-04-11 14:59:33adminsetgithub: 85495
2021-04-16 05:01:32methanesetmessages: + msg391165
2021-04-15 01:17:16methanesetnosy: + methane

pull_requests: + pull_request24150
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