cpython icon indicating copy to clipboard operation
cpython copied to clipboard

GH-125837: Rework the instructions for loading constants and returning values.

Open markshannon opened this issue 1 year ago • 2 comments

Adds:

  • RETURN_VALUE_FUNC
  • RETURN_VALUE_GEN
  • INSTRUMENTED_RETURN_VALUE_FUNC
  • INSTRUMENTED_RETURN_VALUE_GEN
  • LOAD_CONST_IMMORTAL

Removes:

  • RETURN_VALUE
  • RETURN_CONST
  • INSTRUMENTED_RETURN_VALUE
  • INSTRUMENTED_RETURN_CONST
  • Issue: gh-125837

markshannon avatar Oct 23 '24 13:10 markshannon

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.

markshannon avatar Oct 23 '24 14:10 markshannon

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

bedevere-app[bot] avatar Oct 24 '24 09:10 bedevere-app[bot]

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

markshannon avatar Oct 24 '24 16:10 markshannon

Thanks for making the requested changes!

@iritkatriel: please review the changes made to this pull request.

bedevere-app[bot] avatar Oct 24 '24 16:10 bedevere-app[bot]

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.

markshannon avatar Oct 25 '24 14:10 markshannon