This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients nascheme, pablogsal, rhettinger, vstinner
Date 2019-02-16.20:15:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Benchmark show what writes to class variables are anomalously slow.

    class A(object):

    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/
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:18rhettingersetrecipients: + rhettinger, nascheme, vstinner, pablogsal
2019-02-16 20:15:18rhettingersetmessageid: <>
2019-02-16 20:15:18rhettingerlinkissue36012 messages
2019-02-16 20:15:18rhettingercreate