Concerns about performance w/Python, Pysco on Pentiums

Tim Peters tim.one at comcast.net
Fri Mar 7 23:32:45 CET 2003


[Tim]
> Note that the eval loop special-cases list, but not tuple,
> subscripts, in the BINARY_SUBSCR opcode.  list[i] is done inline, tuple[i]
> ends up going thru the generic PyObject_GetItem.  If there's a surprise
> here, then, it's that tuple[i] isn't a *lot* slower than list[i].

[A. Lloyd Flanagan]
> Mostly out of curiousity, is there a reason for that difference, or
> did it sort of 'just work out that way'?

I'm not sure what you're asking.  BINARY_SUBSCR is generated in response to
any subexpression that looks like

    expression1[expression2]

and all such subexpressions can be evaluated by PyObject_GetItem().  The
special case for when expression1 turns out (at runtime) to be a list, and
expression2 turns out (at runtime) to be an int, is (of course) deliberately
aimed at speeding list indexing.  Tuple indexing is surely much rarer, and
every special case slows down all cases it doesn't apply to (e.g., the
special case for list indexing slows down tuple indexing, by the amount of
time it takes to determine that it's not the special case of list indexing).






More information about the Python-list mailing list