[New-bugs-announce] [issue36012] Investigate slow writes to class variables
Raymond Hettinger
report at bugs.python.org
Sat Feb 16 15:15:18 EST 2019
New submission from Raymond Hettinger <raymond.hettinger at 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 <report at bugs.python.org>
<https://bugs.python.org/issue36012>
_______________________________________
More information about the New-bugs-announce
mailing list