[issue42126] Optimize BUILD_CONST_KEY_MAP for distinct keys

Inada Naoki report at bugs.python.org
Fri Oct 23 09:53:46 EDT 2020


Inada Naoki <songofacandy at gmail.com> added the comment:

It is difficult to estimate. Real world applications has different code-style than stdlib. And pyperformance didn't include whole real world applications too.
Some application may use dict display in heavy loop. But it is difficult to say how much exactly.

One example from pyperformance. It uses inner function and function annotations heavily.
BUILD_CONST_KEY_MAP is used to build annotation dict, instead of dict display.
https://github.com/tornadoweb/tornado/blob/5eb7bb8efb4e1be8a2cec1744c857a8dadd43af9/tornado/gen.py

```
591          32 LOAD_CONST               1 ('Future')
             34 LOAD_CONST               2 ('None')
             36 LOAD_CONST               3 (('future', 'return'))
             38 BUILD_CONST_KEY_MAP      5
             40 LOAD_CLOSURE             3 (quiet_exceptions)
             42 BUILD_TUPLE              1
             44 LOAD_CONST               4 (<code object error_callback at 0x7fa7c64195b0, file "/home/inada-n/local/python-dev/lib/python3.10/site-packages/t
ornado/gen.py", line 591>)
             46 LOAD_CONST               5 ('with_timeout.<locals>.error_callback')
             48 MAKE_FUNCTION           12 (annotations, closure)
             50 STORE_DEREF              0 (error_callback)
```

I have not posted pyperformance result because this pull request is based on #41835 and I don't measure each performance.
But #41835 + this is 16% faster than master on bm_tornado_http.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42126>
_______________________________________


More information about the Python-bugs-list mailing list