[issue1045] Performance regression in 2.5
Raymond Hettinger
report at bugs.python.org
Tue Nov 27 19:41:58 CET 2007
Raymond Hettinger added the comment:
FWIW, the 2.4 to 2.5 timing difference came from renaming __len__ to
__length_hint__. This was at Guido's request so that the value of bool
(iter(obj)) would always be True. The consequence of the change was
that we lost the fast slot lookup for __len__ and instead have to do a
dictionary based attribute lookup.
For the most part, I don't care about the overhead as it is constant.
The inner-loop cost dominates. If you do care, the choices are to add
some ugly, hackish specific type checks to bypass the attribute lookup
in cases like generator objects where we know the type is absent. A
more general, cleaner solution is to add a new slot for a length hint.
Personally, I would rather leave this as is and live with the small
constant lookup time. If you concur, please close this report. If
not, please submit a patch for adding a new slot (model the code after
that in PyObject_Size()).
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1045>
__________________________________
More information about the Python-bugs-list
mailing list