New submission from Raymond Hettinger <raymond.hettin...@gmail.com>:
Benchmark show what writes to class variables are anomalously slow. class A(object): pass A.x = 1 # This write is 3 to 5 times slower than other writes. FWIW, the same operation for old-style classes in Python 2.7 was several times faster. We should investigate to understand why the writes are so slow. There might be a good reason or there might be an opportunity for optimization. ------------------------------------------------- $ python3.8 Tools/scripts/var_access_benchmark.py Variable and attribute read access: 4.3 ns read_local 4.6 ns read_nonlocal 14.5 ns read_global 19.0 ns read_builtin 18.4 ns read_classvar_from_class 16.2 ns read_classvar_from_instance 24.7 ns read_instancevar 19.7 ns read_instancevar_slots 19.5 ns read_namedtuple 26.4 ns read_boundmethod Variable and attribute write access: 4.4 ns write_local 5.1 ns write_nonlocal 18.2 ns write_global 103.9 ns write_classvar <== Outlier 35.4 ns write_instancevar 25.6 ns write_instancevar_slots ---------- components: Interpreter Core messages: 335714 nosy: nascheme, pablogsal, rhettinger, vstinner priority: low severity: normal status: open title: Investigate slow writes to class variables type: performance versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue36012> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com