Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use tagged ints for faster iteration #132554

Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-featureA feature request or enhancement
@markshannon

Description

@markshannon

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 andNULL.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp