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.

classification
Title: property performance regression
Type: performance Stage:
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: hovren, rhettinger
Priority: normal Keywords:

Created on 2015-05-19 14:24 by hovren, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg243595 - (view) Author: Hannes Ovrén (hovren) Date: 2015-05-19 14:24
There seems to be a significant regression in performance when using @property in Python 2.x compared to 3.x.

Test code:

class A:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    @property
    def y(self):
        return self._y
    @y.setter
    def y(self, value):
        self._y = value

from timeit import timeit
a = A(1, 2)
timeit('a.x', 'from __main__ import a')
timeit('a.y', 'from __main__ import a')


On my machine (Fedora Linux, x64) I get the following timings:

2.7.8:
a.x : 0.05482792854309082
a.y : 0.05585598945617676

3.4.1:
a.x : 0.06391137995524332
a.y : 0.31193224899470806

I.e. The performace of using a property vs a ordinary member is more or less the same in 2.7, while it incurs a 5x penalty in 3.4.
msg243597 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-05-19 14:37
The test script has a bug.  The class needs to inherit from object in Python 2.7
msg243599 - (view) Author: Hannes Ovrén (hovren) Date: 2015-05-19 14:44
Yes, changing to class A(object) does indeed cause the same magnitude of performance drop in Python 2.7 as well. Thanks!
History
Date User Action Args
2022-04-11 14:58:17adminsetgithub: 68430
2015-05-19 14:44:38hovrensetmessages: + msg243599
2015-05-19 14:37:55rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg243597

resolution: not a bug
2015-05-19 14:24:08hovrencreate