Skip to content
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

Optimize away creation of immediately discarded tuples #99077

Open
markshannon opened this issue Nov 3, 2022 · 1 comment
Open

Optimize away creation of immediately discarded tuples #99077

markshannon opened this issue Nov 3, 2022 · 1 comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Comments

@markshannon
Copy link
Member

This comes from a discussion about whether to issue a syntax warning for one-tuples without parentheses.

Regardless of whether a warning is issued, the following code:

    ...
    a, b
    ...

Creates a tuple then discards it.

  LOAD_FAST                0 (a)
  LOAD_FAST                1 (b)
  BUILD_TUPLE              2
  POP_TOP

we could eliminate the creation of the tuple:

  LOAD_FAST                0 (a)
  LOAD_FAST                1 (b)
  POP_TOP
  POP_TOP
@markshannon markshannon added the performance Performance or resource usage label Nov 3, 2022
@MojoVampire
Copy link
Contributor

MojoVampire commented Nov 3, 2022

Why optimize a useless pattern? I could see a use for optimizing away a tuple when the tuple is indexed and most results discarded, but even that is optimizing for unidiomatic code (people trying to do multiple things in a single expression and only keep the result from one of them).

@iritkatriel iritkatriel added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage
3 participants