You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Handle unpacking of */** arguments and rvalues in the compiler #83501
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2021-08-30.09:13:18.070>created_at=<Date2020-01-13.12:28:10.197>labels= ['interpreter-core', '3.9', 'performance']
title='Handle unpacking of */** arguments and rvalues in the compiler'updated_at=<Date2021-12-18.15:41:31.066>user='https://github.com/markshannon'
Currently the unpacking of starred values in arguments and the right hand side of assignments is handled in the interpreter without any help from the compiler.
The layout of arguments and values is visible to the compiler, so the compiler should do more of the work.
We can replace the complex bytecodes used in unpacking with simpler more focused ones.
Specifically the collection building operations
BUILD_LIST_UNPACK, BUILD_TUPLE_UNPACK, BUILD_SET_UNPACK and BUILD_TUPLE_UNPACK_WITH_CALL
can be replaced with simpler, and self-explanatory operations:
LIST_TO_TUPLE, LIST_EXTEND, SET_UPDATE
In addition, the mapping operations
BUILD_MAP_UNPACK and BUILD_MAP_UNPACK_WITH_CALL
can be replaced with DICT_UPDATE and DICT_MERGE.
DICT_MERGE is like DICT_UPDATE but raises an exception for duplicate keys.
This change would not have much of an effect of performance, as the bytecodes listed are relatively rarely used, but shrinking the interpreter is always beneficial.
Activity
markshannon commentedon Jan 13, 2020
Currently the unpacking of starred values in arguments and the right hand side of assignments is handled in the interpreter without any help from the compiler.
The layout of arguments and values is visible to the compiler, so the compiler should do more of the work.
We can replace the complex bytecodes used in unpacking with simpler more focused ones.
Specifically the collection building operations
BUILD_LIST_UNPACK, BUILD_TUPLE_UNPACK, BUILD_SET_UNPACK and BUILD_TUPLE_UNPACK_WITH_CALL
can be replaced with simpler, and self-explanatory operations:
LIST_TO_TUPLE, LIST_EXTEND, SET_UPDATE
In addition, the mapping operations
BUILD_MAP_UNPACK and BUILD_MAP_UNPACK_WITH_CALL
can be replaced with DICT_UPDATE and DICT_MERGE.
DICT_MERGE is like DICT_UPDATE but raises an exception for duplicate keys.
This change would not have much of an effect of performance, as the bytecodes listed are relatively rarely used, but shrinking the interpreter is always beneficial.
markshannon commentedon Jan 23, 2020
New changeset 13bc139 by Mark Shannon in branch 'master':
bpo-39320: Handle unpacking of *values in compiler (GH-17984)
13bc139
markshannon commentedon Jan 27, 2020
New changeset 8a4cd70 by Mark Shannon in branch 'master':
bpo-39320: Handle unpacking of **values in compiler (GH-18141)
8a4cd70
vstinner commentedon Aug 12, 2020
These changes introduced a regression: bpo-41531 "Python 3.9 regression: Literal dict with > 65535 items are one item shorter".
bharel commentedon Dec 18, 2021
Does this count as a regression or as an unintended bugfix for evaluation order?
https://stackoverflow.com/a/70404659/1658617