Skip to content

Convert DELETE_FAST to LOAD_FAST_CHECK POP_TOP DELETE_FAST as a size optimization #490

@markshannon

Description

@markshannon

Both LOAD_FAST_CHECK and DELETE_FAST check for NULL and raise.
Replacing DELETE_FAST with LOAD_FAST_CHECK; POP_TOP DELETE_FAST could save some space.

How does replacing one instruction with three save space?
Although DELETE_FAST is dynamically rare, DELETE_FAST is statically much more common as it is used in every except Exception as name: block.
Currently at the end of named exception block we emit

LOAD_CONST None
STORE_FAST n
DELETE_FAST n

In the vast majority of these cases we could safely emit just the DELETE_FAST, using the same data flow analysis we use to convert almost all LOAD_FAST_CHECKs into LOAD_FAST

We can implement this by adding DELETE_FAST_CHECKED (for del) and DELETE_FAST_MAYBE_NULL (for the end of named exception blocks) virtual instructions to the compiler.
The data flow analysis would convert them to DELETE_FAST if it can prove that the local is defined.
The backend would convert the remaining DELETE_FAST_CHECKED to LOAD_FAST_CHECK; POP_TOP DELETE_FAST
and the remaining DELETE_FAST_MAYBE_NULL to LOAD_CONST None STORE_FAST DELETE_FAST.

@sweeneyde interested?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions