GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Reorder instructions in with/async-with exception handler to reduce the size of the exception table. · Issue #93621 · python/cpython

Reorder instructions in with/async-with exception handler to reduce the size of the exception table. #93621

New issue
Copy link
New issue
Copy link
Closed
#93622
Closed
Reorder instructions in with/async-with exception handler to reduce the size of the exception table.#93621
#93622
Copy link
Assignees
iritkatriel
Labels
type-featureA feature request or enhancementA feature request or enhancement

Description

@iritkatriel
iritkatriel
opened on Jun 8, 2022
Issue body actions

The dis for this function:

def f1(cm):
    with cm:
        x = 1
    x = 2

is this:

 11           0 RESUME                   0

 12           2 LOAD_FAST                0 (cm)
              4 BEFORE_WITH
              6 POP_TOP

 13           8 LOAD_CONST               1 (1)
             10 STORE_FAST               1 (x)

 12          12 LOAD_CONST               0 (None)
             14 LOAD_CONST               0 (None)
             16 LOAD_CONST               0 (None)
             18 CALL                     2
             28 POP_TOP

 14          30 LOAD_CONST               2 (2)
             32 STORE_FAST               1 (x)
             34 LOAD_CONST               0 (None)
             36 RETURN_VALUE

 12     >>   38 PUSH_EXC_INFO
             40 WITH_EXCEPT_START
             42 POP_JUMP_FORWARD_IF_TRUE     4 (to 52)
             44 RERAISE                  2
        >>   46 COPY                     3
             48 POP_EXCEPT
             50 RERAISE                  1
        >>   52 POP_TOP
             54 POP_EXCEPT
             56 POP_TOP
             58 POP_TOP

 14          60 LOAD_CONST               2 (2)
             62 STORE_FAST               1 (x)
             64 LOAD_CONST               0 (None)
             66 RETURN_VALUE
ExceptionTable:
  6 to 10 -> 38 [1] lasti
  38 to 44 -> 46 [3] lasti
  52 to 52 -> 46 [3] lasti

Note the last row of the exception table: inst 52 goes to 46, same as 38-44. We can reorder the code so that this block is consecutive, and we save one entry in the exception table for each with/async with:

 11           0 RESUME                   0

 12           2 LOAD_FAST                0 (cm)
              4 BEFORE_WITH
              6 POP_TOP

 13           8 LOAD_CONST               1 (1)
             10 STORE_FAST               1 (x)

 12          12 LOAD_CONST               0 (None)
             14 LOAD_CONST               0 (None)
             16 LOAD_CONST               0 (None)
             18 CALL                     2
             28 POP_TOP

 14          30 LOAD_CONST               2 (2)
             32 STORE_FAST               1 (x)
             34 LOAD_CONST               0 (None)
             36 RETURN_VALUE

 12     >>   38 PUSH_EXC_INFO
             40 WITH_EXCEPT_START
             42 POP_JUMP_FORWARD_IF_TRUE     1 (to 46)
             44 RERAISE                  2
        >>   46 POP_TOP
             48 POP_EXCEPT
             50 POP_TOP
             52 POP_TOP

 14          54 LOAD_CONST               2 (2)
             56 STORE_FAST               1 (x)
             58 LOAD_CONST               0 (None)
             60 RETURN_VALUE
        >>   62 COPY                     3
             64 POP_EXCEPT
             66 RERAISE                  1
ExceptionTable:
  6 to 10 -> 38 [1] lasti
  38 to 46 -> 62 [3] lasti

Activity

  1. iritkatriel
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Jun 8, 2022
  2. iritkatriel
    self-assigned this
    on Jun 9, 2022
  3. iritkatriel
    closed this as completedin #93622on Jun 10, 2022
  4. iritkatriel
    added a commit that references this issue on Jun 10, 2022

    GH-93621: reorder code in with/async-with exception exit path to redu…

    cf730b5
  5. serhiy-storchaka
    added a commit that references this issue on Jun 26, 2022

    Revert 30935 defer bpo45162 to 312 (#94285)

    1ffde3e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @iritkatriel
    iritkatriel

Labels

type-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.