This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: fast tuple[index] by inlining on BINARY_SUBSCR
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: loewis, ocean-city, rhettinger
Priority: normal Keywords: patch

Created on 2007-01-07 05:51 by ocean-city, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fast tuple[i].patch ocean-city, 2007-01-07 05:51
statistics.patch ocean-city, 2007-01-08 05:49
Messages (5)
msg51686 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2007-01-07 05:51
Hello.

I noticed there is speed difference between

  a = [0,] # list
  a[0] # fast

and

  a = (0,) # tuple
  a[0] # slow

while solving ICPC puzzle with Python.

I thought this is wierd because, indeed tuple is readonly, there is no conceptual difference between list and tuple when 'extract' item from them.

After investigation, I found this difference comes from the shortcut for list on ceval.c (BINARY_SUBSCR).

Is it valuable to put shortcut for tuple too? I'll attach the patch for release-maint25 branch. Thank you.
msg51687 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-01-07 21:34
It would be helpful to get some statistics on how often this occurs: of all case of BINARY_SUBSCR, how man refer to tuples, how many to lists, and how many to other objects?

To get some data, you can measure a run of a test suite, or a run of IDLE, or of compileall.
msg51688 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2007-01-08 03:56
I recommend against this.

Any additional specialization code will necessarily slow down other cases handled by PyObject_GetItem.  So, the merits of speeding-up tuple indexing need to be weighed against the costs (slowing down other code and the excess loading of ceval.c with specialization code).

Also, I reject the premise that there is no conceptual difference between list and tuple indexing.  The former is a primary use case for lists and the latter is only incidental to tuple use cases (see the endless discussions on python-dev and comp.lang.python about why tuples are not to be regarded as immutable lists and in fact have a different intended set of uses).
msg51689 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2007-01-08 05:49
Sorry, I want to withdraw this.

Python/lib/test/testall.py
===> list: 2541719, tuple: 620815, other: 6174214

The ratio of tuple seems relatively low.
File Added: statistics.patch
msg51690 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2007-01-08 06:58
>see the endless discussions on python-dev...

Thank you, rhettinger. I'm interested in it. I'll see them.
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44423
2007-01-07 05:51:17ocean-citycreate