This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients Demur Rumed, benjamin.peterson, brett.cannon, georg.brandl, ncoghlan, serhiy.storchaka, vstinner, yselivanov
Date 2016-05-30.09:31:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1464600679.25.0.054376782296.issue27140@psf.upfronthosting.co.za>
In-reply-to
Content
Proposed patch adds the BUILD_MAP_EX opcode (maybe somebody propose better name?). It takes values from the stack and keys from the tuple on the top of the stack. Currently it affects only creating a dict with const keys and calling a function with keywords after the var-keyword argument.

$ echo "{'a': 1, 'b': 2, 'c': 3}" | ./python -m dis

Unpatched:

  1           0 LOAD_CONST               0 ('a')
              2 LOAD_CONST               1 (1)
              4 LOAD_CONST               2 ('b')
              6 LOAD_CONST               3 (2)
              8 LOAD_CONST               4 ('c')
             10 LOAD_CONST               5 (3)
             12 BUILD_MAP                3
             14 POP_TOP
             16 LOAD_CONST               6 (None)
             18 RETURN_VALUE

Patched:

  1           0 LOAD_CONST               0 (1)
              2 LOAD_CONST               1 (2)
              4 LOAD_CONST               2 (3)
              6 LOAD_CONST               7 (('a', 'b', 'c'))
              8 BUILD_MAP_EX             3
             10 POP_TOP
             12 LOAD_CONST               6 (None)
             14 RETURN_VALUE

$ echo "f(**kw, a=1, b=2, c=3)" | ./python -m dis

Unpatched:

  1           0 LOAD_NAME                0 (f)
              2 LOAD_NAME                1 (kw)
              4 LOAD_CONST               0 ('a')
              6 LOAD_CONST               1 (1)
              8 LOAD_CONST               2 ('b')
             10 LOAD_CONST               3 (2)
             12 LOAD_CONST               4 ('c')
             14 LOAD_CONST               5 (3)
             16 BUILD_MAP                3
             18 EXTENDED_ARG             1
             20 BUILD_MAP_UNPACK_WITH_CALL   258
             22 CALL_FUNCTION_KW         0 (0 positional, 0 keyword pair)
             24 POP_TOP
             26 LOAD_CONST               6 (None)
             28 RETURN_VALUE

Patched:

  1           0 LOAD_NAME                0 (f)
              2 LOAD_NAME                1 (kw)
              4 LOAD_CONST               0 (1)
              6 LOAD_CONST               1 (2)
              8 LOAD_CONST               2 (3)
             10 LOAD_CONST               7 (('a', 'b', 'c'))
             12 BUILD_MAP_EX             3
             14 EXTENDED_ARG             1
             16 BUILD_MAP_UNPACK_WITH_CALL   258
             18 CALL_FUNCTION_KW         0 (0 positional, 0 keyword pair)
             20 POP_TOP
             22 LOAD_CONST               6 (None)
             24 RETURN_VALUE

It could be more useful for new MAKE_FUNCTION opcode (issue27095) and maybe for new CALL_FUNCTION* opcodes.

The benefit of BUILD_MAP_EX is less LOAD_CONST instructions and less stack consuming.
History
Date User Action Args
2016-05-30 09:31:20serhiy.storchakasetrecipients: + serhiy.storchaka, brett.cannon, georg.brandl, ncoghlan, vstinner, benjamin.peterson, yselivanov, Demur Rumed
2016-05-30 09:31:19serhiy.storchakasetmessageid: <1464600679.25.0.054376782296.issue27140@psf.upfronthosting.co.za>
2016-05-30 09:31:19serhiy.storchakalinkissue27140 messages
2016-05-30 09:31:18serhiy.storchakacreate