Message335714
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 |
|
Date |
User |
Action |
Args |
2019-02-16 20:15:18 | rhettinger | set | recipients:
+ rhettinger, nascheme, vstinner, pablogsal |
2019-02-16 20:15:18 | rhettinger | set | messageid: <1550348118.4.0.228746523417.issue36012@roundup.psfhosted.org> |
2019-02-16 20:15:18 | rhettinger | link | issue36012 messages |
2019-02-16 20:15:18 | rhettinger | create | |
|