python / python/cpython

Remove `DELETE_FAST` bytecode instruction

Open
#145,749 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.15 interpreter-core performance
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

DELETE_FAST has two uses:

  1. delete var where var is a local variable
  2. Cleaning up at the end of a named exception block.

A local variable can be deleted with the sequence PUSH_NULL; STORE_FAST var.

Deleting a local variable

Instead of DELETE_FAST n we can emit LOAD_FAST n; POP_TOP n; PUSH_NULL; STORE_FAST n which the bytecode optimizer will reduce to PUSH_NULL; STORE_FAST n in most cases.

Cleaning up at the end of a named exception block.

We currently emit the sequence: LOAD_CONST None; STORE_FAST n; DELETE_FAST n
which can be replaced with PUSH_NULL; STORE_FAST n

This case is far more common than explicitly deleting a local variable, so we can reduce code size as well as freeing up an opcode.


See https://github.com/faster-cpython/ideas/issues/490

Linked PRs
  • gh-145983

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the compiler entry points that emit DELETE_FAST for local deletion and named-exception cleanup. Compare their bytecode output with the proposed PUSH_NULL; STORE_FAST sequences, then verify that DELETE_FAST is no longer emitted and existing bytecode tests still pass; the issue references linked PR gh-145983.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.