Skip to content

Optimize list iteration #36649

Closed
Closed

Description

@rhettinger
BPO 560736
Nosy @gvanrossum, @rhettinger
Files
  • list.diff: Patch to add list iterator
  • list2.diff: Revised patch using PyList_Check()
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2002-05-31.21:38:09.000>
    created_at = <Date 2002-05-26.15:25:24.000>
    labels = ['interpreter-core']
    title = 'Optimize list iteration'
    updated_at = <Date 2002-05-31.21:38:09.000>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2002-05-31.21:38:09.000>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2002-05-26.15:25:24.000>
    creator = 'rhettinger'
    dependencies = []
    files = ['4298', '4299']
    hgrepos = []
    issue_num = 560736
    keywords = ['patch']
    message_count = 5.0
    messages = ['40134', '40135', '40136', '40137', '40138']
    nosy_count = 2.0
    nosy_names = ['gvanrossum', 'rhettinger']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue560736'
    versions = ['Python 2.3']

    Activity

    1. rhettinger commented on May 26, 2002

      @rhettinger
      ContributorAuthor

      Filled listobject's tp_iter slot with it's own iterator.
      Speeds looping 5 to 10% (YMMV).

      Only half of the speed-up comes from using tp_iter.
      The rest came from code tweaking:
      -- eliminate the it variable
      -- invert the limit test to avoid jumps
      -- bypass the GET_ITEM macro to allow index++ to be
      combined with the lookup.

    2. self-assigned this
      on May 26, 2002
    3. self-assigned this
      on May 26, 2002
    4. gvanrossum commented on May 31, 2002

      @gvanrossum
      Member

      Logged In: YES
      user_id=6380

      Very close. It looks like you are using PySequence_Check()
      where you should be using PyList_Check() though, since
      listiter_next() really needs it to be a list! (Two place
      have this mistake.)

      Apart from that, it's good! (Note that the speedup
      percentage is better when you use -O. :-)

    5. rhettinger commented on May 31, 2002

      @rhettinger
      ContributorAuthor

      Logged In: YES
      user_id=80475

      Replaced both instances with PyList_Check().
      No other changes.
      Re-verified compile, timings, and regression tests.

      Okay to commit?

    6. gvanrossum commented on May 31, 2002

      @gvanrossum
      Member

      Logged In: YES
      user_id=6380

      Go ahead, and then close this issue!

    7. rhettinger commented on May 31, 2002

      @rhettinger
      ContributorAuthor

      Logged In: YES
      user_id=80475

      Committed as listobject.c 2.107 and iterobject.c 1.10

      Closing patch.

    8. transferred this issue fromon Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions