[issue2115] __slots__ make attribute setting 10x slower

2008-02-15 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc added the comment: I think I fixed the issue. "svn annotate" showed that the exact same optimization was applied on __slots__ read access, five years ago: r28297. -- resolution: -> fixed status: open -> closed __ Tracker <[EMAIL PROT

[issue2115] __slots__ make attribute setting 10x slower

2008-02-15 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc added the comment: __instancecheck__ is not only slower, it can also cause crashes: import abc class MyABC: __metaclass__ = abc.ABCMeta __slots__ = ["a"] class Unrelated: pass MyABC.register(Unrelated) u=Unrelated() assert isinstance(u, MyABC) MyABC.a.__set__(

[issue2115] __slots__ make attribute setting 10x slower

2008-02-14 Thread Christian Heimes
Christian Heimes added the comment: Thomas Heller wrote: > BTW; calling PyObject_GetAttr() with interned strings for > "__instancecheck__" and "__subclasscheck__" brings not enough speedup. I've implemented the interning as static PyObject* in r60822. It should give a small speedup. ___

[issue2115] __slots__ make attribute setting 10x slower

2008-02-14 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc added the comment: With this trivial patch, all tests still pass: Index: Objects/descrobject.c === --- Objects/descrobject.c (revision 60754) +++ Objects/descrobject.c (working copy) @@ -166,7 +166,7

[issue2115] __slots__ make attribute setting 10x slower

2008-02-14 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc added the comment: Something interesting: - attribute setting uses PyObject_IsInstance, which is slower since the introduction of ABCs. - attribute reading uses PyObject_TypeCheck, which only searches the __mro__. Does this means that many calls to IsInstance could be replac

[issue2115] __slots__ make attribute setting 10x slower

2008-02-14 Thread Thomas Heller
Thomas Heller added the comment: PyObject_IsSubclass() has the same problem. BTW; calling PyObject_GetAttr() with interned strings for "__instancecheck__" and "__subclasscheck__" brings not enough speedup. __ Tracker <[EMAIL PROTECTED]>

[issue2115] __slots__ make attribute setting 10x slower

2008-02-14 Thread Christian Heimes
Christian Heimes added the comment: I agree, Thomas -- nosy: +tiran priority: -> high __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bugs-list ma

[issue2115] __slots__ make attribute setting 10x slower

2008-02-14 Thread Thomas Heller
Thomas Heller added the comment: I think this is a serious problem (and thanks, amaury, for finding the spot). comtypes, like ctypes, uses quite a bit of isinstance calls. It is the reason that the comtypes unit tests run between 8% and 25% slower with trunk than with python 2.5.1. If I comment

[issue2115] __slots__ make attribute setting 10x slower

2008-02-14 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc added the comment: This slowdown is due to the new implementation of isinstance in python2.6. If I comment most of the code of PyObject_IsInstance in Objects/abstract.c (remove all __instancecheck__ stuff; leave only the last line), timings are much better, and more similar

[issue2115] __slots__ make attribute setting 10x slower

2008-02-14 Thread Facundo Batista
Changes by Facundo Batista: -- nosy: +facundobatista __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bugs-list mailing list Unsubscribe: http://m

[issue2115] __slots__ make attribute setting 10x slower

2008-02-14 Thread Jeffrey Yasskin
New submission from Jeffrey Yasskin: (On a MacBook Pro 2.33 GHz) $ ./python.exe -m timeit -s 'class Foo(object): pass' -s 'f = Foo()' 'f.num = 3' 1000 loops, best of 3: 0.13 usec per loop $ ./python.exe -m timeit -s 'class Foo(object): __slots__ = ["num"]' -s 'f = Foo()' 'f.num = 3' 100