ytrstu / pyeuclid

Automatically exported from code.google.com/p/pyeuclid
0 stars 0 forks source link

__slots__, performance, side-effects and modern python #23

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
In-code documentation of _use_slots says that *not* using it is "much faster 
than slots in current versions of Python (2.4 and 2.5)". To be fair, it also 
says that in future versions it might be faster.

Does that statement still hold in 2014?

In a few tests I did with python 2.7.4, using slots was consistently faster by 
~10%. All my google searches about the subject also indicate that performance 
is indeed better.

Perhaps the performance hit was due to old/new class style instead? Which 
brings me to another question: Is there any benefit in using old-style classes 
in modern python? If not, new classes should be used regardless of using slots 
or not.

It does not mean using slots is a no-brainer, win-win: not having a __dict__ 
have some subtle side-effects to classes instances. By the way: are those 
side-effects relevant to euclid? Maybe docs sh

Also, documentation says slots are 'memory efficient', it should clarify that 
'efficiency' means 'uses less memory': it deals about size/footprint. 'Memory 
Usage' is perhaps a better wording. It should also clarify that savings is 
proportional to number of *instances* created (a likely use-case when dealing 
with vectors and points)

So the real decision is not Performance VS Memory Efficiency, but (Performance 
+ Memory Usage) VS the side-effects of __slots__.

Sorry for bringing so many issues in a single bug report, but I feel they are 
all related.

Original issue reported on code.google.com by rodrigo....@gmail.com on 6 Aug 2014 at 6:39