-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
import re
[x for x in [] if re.match(".*", x)]
vs:
import re
re.match(".*", x)
When you disassemble these you'll see the inlined one will be doing a LOAD_ATTR 3 (match + NULL|self) while the one outside of the comprehension will be doing a PUSH_NULL/CALL which is to disable the method call optimization on things which are likely not methods.
These should both have the same byte code. There's no perceivable code execution difference other than performance though.
CPython versions tested on:
3.12, CPython main branch
Operating systems tested on:
Linux
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error