Title: Redundant jump instructions due to deleted unreachable bytecode blocks
Type: performance Stage: resolved
Components: Versions: Python 3.10
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, OmG
Priority: normal Keywords: patch

Created on 2020-12-10 16:47 by OmG, last changed 2020-12-16 14:43 by OmG. This issue is now closed.

File name Uploaded Description Edit OmG, 2020-12-10 16:47 This file contains a short function that exhibits this behavior. Notice the JUMP_FORWARD 0 instruction, which does nothing.
Pull Requests
URL Status Linked Edit
PR 23733 merged OmG, 2020-12-10 16:48
Messages (2)
msg382834 - (view) Author: Om G (OmG) * Date: 2020-12-10 16:47
During optimization, the compiler deletes blocks that are marked as unreachable. In doing so, it can render jump instructions that used to jump over the now-deleted blocks redundant, since simply falling through to the next non-empty block is now equivalent.

An example of a place where this occurs is around "if condition: statement; else: break" style structures (see attached proof of concept code below), but this is a general case and could occur in other places.

Tested on the latest 3.10 branch including all recent compile.c changes.
msg383157 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2020-12-16 12:18
New changeset c71581c7a4192e6ba9a79eccc583aaadab300efa by Om G in branch 'master':
bpo-42615: Delete redundant jump instructions that only bypass empty blocks (GH-23733)
Date User Action Args
2020-12-16 14:43:48OmGsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-12-16 12:18:25Mark.Shannonsetnosy: + Mark.Shannon
messages: + msg383157
2020-12-10 16:48:53OmGsetkeywords: + patch
stage: patch review
pull_requests: + pull_request22591
2020-12-10 16:47:13OmGcreate