gh-145858: Remove DELETE_DEREF bytecode instruction#148185
Open
Siyet wants to merge 4 commits intopython:mainfrom
Open
gh-145858: Remove DELETE_DEREF bytecode instruction#148185Siyet wants to merge 4 commits intopython:mainfrom
Siyet wants to merge 4 commits intopython:mainfrom
Conversation
Replace DELETE_DEREF with the sequence LOAD_DEREF + POP_TOP + PUSH_NULL + STORE_DEREF in the compiler. Adapt STORE_DEREF to handle NULL stackref for cell clearing.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
| @@ -1 +1,2 @@ | |||
| # HTML IDs excluded from the check-html-ids.py check. | |||
| library/dis.html: opcode-DELETE_DEREF | |||
Member
There was a problem hiding this comment.
I would suggest instead having a 'CPython bytecode changes' section in the what's new, like we had for 3.14, and redirecting to there, but this isn't my area so I'll leave it to the experts.
Author
There was a problem hiding this comment.
Good point, thanks! Added a "CPython bytecode changes" section to Doc/whatsnew/3.15.rst following the 3.14 pattern. Kept removed-ids.txt as well since it's needed for the CI HTML ID check independently.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Remove the
DELETE_DEREFopcode by replacing it in the compiler with theequivalent sequence
LOAD_DEREF+POP_TOP+PUSH_NULL+STORE_DEREF.This frees up one opcode slot. Since deletion of closure variables is
practically never used, the extra instructions have no measurable cost.
Changes
codegen_nameop()now emits a 4-instruction sequenceinstead of
DELETE_DEREFforDelcontext on deref variablesDELETE_DEREFinstruction definition;adapt
STORE_DEREFto handleNULLstackref (needed for cell clearing)DELETE_DEREFfrom offset fixup switchPYC_MAGIC_NUMBER3663 → 3664Test plan
test_scope,test_dis,test_compile,test_compiler_assemble,test_peepholer,test_opcodes— all passrefcount/leak detection, nested closures, 8-thread concurrent del
Stress test script
stress_delete_deref.py
Benchmark script
bench_delete_deref.py
Results (free-threading debug build, dedicated server,
taskset -c 0)DELETE_DEREFbytecode instruction #145858📚 Documentation preview 📚: https://cpython-previews--148185.org.readthedocs.build/