GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use tagged ints for faster iteration · Issue #132554 · python/cpython

Use tagged ints for faster iteration #132554

New issue
Copy link
New issue
Copy link
Open
Open
Use tagged ints for faster iteration#132554
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement

Description

@markshannon
markshannon
opened on Apr 15, 2025
Issue body actions

Iteration over tuples and short lists is quite inefficient as we need to create an iterator object, only to have to destroy it again moments later. Not only that, fetching values from iterators involves additional indirection compared to fetching them from sequences.

Instead we can push a pair of values to the stack. For common sequences, like tuple, list, strings, some ranges and a few others, we push the sequence and the integer index (initially 0) to the stack. For other iterables, we push the iterator and NULL.

GET_ITER will have the signature:
iterable -- iter, index_or_null
FOR_ITER now has the signature:
iter, index_or_null -- iter, index_or_null, next.

What makes this efficient is tagged integers. By using tagged integers, no objects need to be created.

Examples

GET_ITER

[ <tuple at ...> ] -> [ <tuple at ...>, 0 ]

[ <file at ...> ] -> [ <file iterator at ...>, NULL ]

FOR_ITER

[ <tuple at ...>, 0 ] -> [ <tuple at ...>, 1, item0 ]

[ <file iterator at ...>, NULL ] -> [ <file iterator at ...>, NULL, line ]

Linked PRs

  • GH-132554: "Virtual" iterators #132555
  • GH-132554: Add stats for GET_ITER #132592
  • GH-132554: Specialize GET_ITER and FOR_ITER for range #135063
  • GH-132554: Fix tier2 FOR_ITER implementation and optimizations #135137

Activity

  1. markshannon commented on Apr 15, 2025

    @markshannon
    markshannon
    on Apr 15, 2025
    MemberAuthor
    More actions

    Faster CPython discussion

    Tagged ints issue

  2. picnixz
    added
    type-featureA feature request or enhancementA feature request or enhancement
    performancePerformance or resource usagePerformance or resource usage
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Apr 17, 2025
  3. mdboom
    self-assigned this
    on Apr 21, 2025
  4. mdboom commented on Apr 21, 2025

    @mdboom
    mdboom
    on Apr 21, 2025
    Contributor
    More actions

    As discussed in our meeting, I'm going to take a first crack at this.

  5. mdboom
    removed their assignment
    on Apr 21, 2025
  6. mdboom commented on Apr 21, 2025

    @mdboom
    mdboom
    on Apr 21, 2025
    Contributor
    More actions

    As discussed in our meeting, I'm going to take a first crack at this.

    Actually, realizing @markshannon already started that, I'm instead going to follow-on and do GET_ITER specializations.

  7. markshannon
    added a commit that references this issue on Apr 29, 2025

    GH-132554: Add stats for GET_ITER (GH-132592)

    622300b
  8. markshannon
    added a commit that references this issue on May 27, 2025

    GH-132554: "Virtual" iterators (GH-132555)

    f6f4e8a
  9. markshannon
    added a commit that references this issue on Jun 5, 2025

    GH-132554: Fix tier2 `FOR_ITER` implementation and optimizations (GH-…

    b90ecea
  10. Pranjal095
    added 2 commits that reference this issue on Jul 12, 2025

    pythonGH-132554: "Virtual" iterators (pythonGH-132555)

    03f4000

    pythonGH-132554: Fix tier2 `FOR_ITER` implementation and optimizations (

    3557d29
  11. taegyunkim
    added 2 commits that reference this issue on Aug 4, 2025

    pythonGH-132554: "Virtual" iterators (pythonGH-132555)

    b3fb901

    pythonGH-132554: Fix tier2 `FOR_ITER` implementation and optimizations (

    dd6f0ca
  12. Agent-Hellboy
    added a commit that references this issue on Aug 19, 2025

    pythonGH-132554: Fix tier2 `FOR_ITER` implementation and optimizations (

    e7ac90f
  13. gostak-dd
    added a commit that references this issue on Jun 2, 2026

    pythonGH-132554: "Virtual" iterators (pythonGH-132555)

    88df9e9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.