Skip to content

Refactor RETURN_VALUE and RETURN_CONST #125837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
markshannon opened this issue Oct 22, 2024 · 0 comments
Closed

Refactor RETURN_VALUE and RETURN_CONST #125837

markshannon opened this issue Oct 22, 2024 · 0 comments
Labels
3.14 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Comments

@markshannon
Copy link
Member

markshannon commented Oct 22, 2024

The RETURN_VALUE and RETURN_CONST instructions return the value on top of the stack and a constant, respectively.
RETURN_CONST is effectively a superinstruction: LOAD_CONST + RETURN_VALUE.

This worked well up to 3.13, but is likely to be an impediment to further optimizations:

  • The JIT already breaks RETURN_CONST into LOAD_CONST and RETURN_VALUE so the superinstruction has no value.
  • RETURN_VALUE has two different paths internally, one for normal functions and the other for generators. We know statically which sort of function we are in, so we should emit different bytecodes for the different behavior
  • With the proposed changes to reference counting, it will help in the interpreter (we already do this in the JIT) to have a different instruction for immortal constants. (This might only be temporarily, as we expect to be able to defer reference counting on all constants)

Changes to the instruction set:

  • RETURN_CONST and INSTRUMENTED_RETURN_CONST will be removed.
  • RETURN_VALUE_GEN, INSTRUMENTED_RETURN_GEN and LOAD_CONST_IMMORTAL will be added.

We expect that LOAD_CONST_IMMORTAL will be removed again before 3.14, but that is not a requirement.

Linked PRs

@markshannon markshannon added performance Performance or resource usage 3.14 bugs and security fixes labels Oct 22, 2024
@Eclips4 Eclips4 added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Oct 22, 2024
markshannon added a commit that referenced this issue Oct 29, 2024
* Add LOAD_CONST_IMMORTAL opcode

* Add LOAD_SMALL_INT opcode

* Remove RETURN_CONST opcode
picnixz pushed a commit to picnixz/cpython that referenced this issue Dec 8, 2024
* Add LOAD_CONST_IMMORTAL opcode

* Add LOAD_SMALL_INT opcode

* Remove RETURN_CONST opcode
ebonnal pushed a commit to ebonnal/cpython that referenced this issue Jan 12, 2025
* Add LOAD_CONST_IMMORTAL opcode

* Add LOAD_SMALL_INT opcode

* Remove RETURN_CONST opcode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage
Projects
None yet
Development

No branches or pull requests

2 participants