Hi Simon, On Tue, Mar 29, 2011 at 12:07:15PM -0700, Simon King wrote: > Hi! > > Tickets #9944 and #9138 provide some nice features, but slow things > down. It seems to me that the reason of the performance loss is that > the patches from these tickets make the method resolution order of > polynomial rings much longer - in some cases the length doubles (15 > versus 39 steps until <type 'object'> is reached). > > As much as I understand: If the mro is longer than Python needs more > time to look up a method that is defined for a very basic class (such > as sage.structure.category_object.CategoryObject or > sage.structure.parent.Parent).
I may be wrong but I have the impression that there is a cache here: Let's create a long mro class End(object): def toto(self): return 1 def long_mro(n): if n == 0: return End else: class New(long_mro(n-1)): pass return New obj_long = long_mro(500)() obj_end = End() Then after that: sage: len(type(obj_long).mro()) 502 sage: len(type(obj_end).mro()) 2 sage: timeit('obj_long.toto()',number=10^6) 1000000 loops, best of 3: 187 ns per loop sage: timeit('obj_end.toto()',number=10^6) 1000000 loops, best of 3: 188 ns per loop So it seems that there is no difference... Well actually I just figured out that this has something to do with Cython: if I change class End(object): to class End(SageObject): Then: sage: timeit('obj_long.toto()',number=10^6) 1000000 loops, best of 3: 9.22 盜 per loop sage: timeit('obj_end.toto()',number=10^6) 1000000 loops, best of 3: 203 ns per loop Now we see the difference. Maybe it's a bug... I'll as on Cython-dev. Cheers, Florent -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org