Page MenuHomePhabricator

use dict literals to initialize python dictionaries
ClosedPublic

Authored by PiRK on Apr 8 2023, 15:04.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABCe069ace68eb3: use dict literals to initialize python dictionaries
Summary

It is more pythonic and slightly faster.

$ python
Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import timeit
>>> timeit.timeit("d = {}")
0.023977567000656563
>>> timeit.timeit("d = dict()")
0.050307012000303075
>>>
>>> import dis
>>> def f(): return {}
>>> def g(): return dict()
>>> dis.dis(f)
  1           0 BUILD_MAP                0
              2 RETURN_VALUE
>>> dis.dis(g)
  1           0 LOAD_GLOBAL              0 (dict)
              2 CALL_FUNCTION            0
              4 RETURN_VALUE

Depends D13636

Test Plan

build/test/functional/test_runner.py feature_tx_version
python contrib/devtools/circular-dependencies.py

These changes are hopefully trivial enough to not have to run the tracing scripts.

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable