gh-145858: Remove DELETE_DEREF bytecode instruction#148185
gh-145858: Remove DELETE_DEREF bytecode instruction#148185Siyet 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 | |||
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.
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 PR is stale because it has been open for 30 days with no activity. |
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/