[Python-Dev] Why does STORE_MAP not take a parameter?

Neil Girdhar mistersheik at gmail.com
Wed Jan 21 11:16:26 CET 2015


Building argument lists and dicts in python entails the following opcode
pattern:

  1           0 BUILD_MAP                3
              3 LOAD_CONST               0 (2)
              6 LOAD_CONST               1 (1)
              9 STORE_MAP
             10 LOAD_CONST               2 (4)
             13 LOAD_CONST               3 (3)
             16 STORE_MAP
             17 LOAD_CONST               4 (6)
             20 LOAD_CONST               5 (5)
             23 STORE_MAP

Building lists on the other hand works like this:

  1           0 LOAD_CONST               0 (1)
              3 LOAD_CONST               1 (2)
              6 LOAD_CONST               2 (3)
              9 BUILD_LIST               3


Why not have BUILD_MAP work like BUILD_LIST?   I.e., STORE_MAP takes a
parameter n and adds the last n pairs of stack elements into the n-1 stack
element (the dictionary).

This means that the data would live on the stack until it is all suddenly
transferred to the dict, but I'm not sure about the effect on performance
(whether positive or negative).

It does save on instruction cache misses.

It should be an easy change to implement since all calls to BUILD_MAP could
be replaced with "BUILD_MAP 1" and then optimized later.

Best,

Neil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150121/3130a8fe/attachment.html>


More information about the Python-Dev mailing list