Open markshannon opened 1 year ago
Sure, I can work on this.
Another thing to look at, as you had suggested at one point, is that there could be a NULL_CHECK instruction, and that would work for both LOAD_FAST and DELETE_FAST. That should become possible once https://github.com/python/cpython/pull/99075 is merged.
NULL_CHECK; DELETE_FAST(unchecked)
and LOAD_FAST_CHECK; DELETE_FAST(unchecked)
are equivalent.
The question is which is faster. Are there more loads that need checking, or more deletes that need checking? I suspect that there are very few of each.
Both
LOAD_FAST_CHECK
andDELETE_FAST
check forNULL
and raise. ReplacingDELETE_FAST
withLOAD_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 everyexcept Exception as name:
block. Currently at the end of named exception block we emitIn 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 allLOAD_FAST_CHECK
s intoLOAD_FAST
We can implement this by adding
DELETE_FAST_CHECKED
(fordel
) andDELETE_FAST_MAYBE_NULL
(for the end of named exception blocks) virtual instructions to the compiler. The data flow analysis would convert them toDELETE_FAST
if it can prove that the local is defined. The backend would convert the remainingDELETE_FAST_CHECKED
toLOAD_FAST_CHECK; POP_TOP DELETE_FAST
and the remainingDELETE_FAST_MAYBE_NULL
toLOAD_CONST None STORE_FAST DELETE_FAST
.@sweeneyde interested?