GH-125837: Rework the instructions for loading constants and returning values.
Adds:
RETURN_VALUE_FUNCRETURN_VALUE_GENINSTRUMENTED_RETURN_VALUE_FUNCINSTRUMENTED_RETURN_VALUE_GENLOAD_CONST_IMMORTAL
Removes:
RETURN_VALUERETURN_CONSTINSTRUMENTED_RETURN_VALUEINSTRUMENTED_RETURN_CONST
- Issue: gh-125837
Performance impact without the JIT is in the noise. Nominally 0.2% slower
Performance impact with the JIT is also in the noise. Nominally 0.2% faster.
Stats shows that almost 90% of LOAD_CONST are converted to LOAD_CONST_IMMORTAL. There is a 3% increase in EXTENDED_ARG due to LOAD_CONST RETURN_VALUE taking more space than RETURN_CONST.
My hypothesis is that the slowdown caused by extra dispatching is mostly offset by the more efficient LOAD_CONST in tier 1 and more streamlined RETURN_VALUEs.
In tier 2 there is no extra overhead for dispatching, which might be why we see a tiny speedup instead of a tiny slowdown.
When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.
The magic comment is "I have made the requested changes; please review again". I haven't, but I think I've justified my decisions. @iritkatriel
Thanks for making the requested changes!
@iritkatriel: please review the changes made to this pull request.
I'm closing this for now. We can revisit splitting up RETURN_VALUE when the full refactoring I suggested above is ready.
https://github.com/python/cpython/pull/125972 splits up LOAD_CONST and removes RETURN_CONST and shows slightly better performance.