FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GH-132554: "Virtual" iterators by markshannon · Pull Request #132555 · python/cpython · GitHub

/ cpython Public

GH-132554: "Virtual" iterators - #132555

Merged
markshannon merged 29 commits into
python:mainfrom
faster-cpython:virtual-iterators
May 27, 2025
Merged

GH-132554: "Virtual" iterators#132555
markshannon merged 29 commits into
python:mainfrom
faster-cpython:virtual-iterators

Conversation

markshannon commented Apr 15, 2025
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

Just a draft PR until I have performance numbers.

Copy link
Copy Markdown
Member Author

Performance is good. Nothing amazing, but a small speedup.

Stats show no significant changes

Comment thread Python/specialize.c Outdated
Comment thread Python/stackrefs.c
Comment thread Python/ceval.c Outdated
Comment thread Python/ceval.c Outdated
Comment thread Python/ceval.c Outdated
Comment thread Python/specialize.c

Copy link
Copy Markdown
Member

@markshannon I don't think it matters here, but you didn't update in https://github.com/python/cpython/pull/132545/files Py_TAG_BITS to 3. It's still 1. I know it "technically" doesn't matter because we use a bitshift to zero it out, but we should still update it to be consistent.

Copy link
Copy Markdown
Member Author

@markshannon I don't think it matters here, but you didn't update in https://github.com/python/cpython/pull/132545/files Py_TAG_BITS to 3. It's still 1. I know it "technically" doesn't matter because we use a bitshift to zero it out, but we should still update it to be consistent.

Fixed in #134244

Comment thread Include/internal/pycore_stackref.h Outdated
static inline _PyStackRef
PyStackRef_IncrementTaggedIntNoOverflow(_PyStackRef ref)
{
assert(ref.bits != (uintptr_t)-1); // Deosn't overflow

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't understand why you use this condition. Should it not be assert(ref.bits + 4 > ref.bits) or something like that?

Comment thread Include/internal/pycore_stackref.h Outdated
return false;
}
return PyFunction_Check(PyStackRef_AsPyObjectBorrow(stackref));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Would it help to define these via a macro? Something like

#define STACKREF_CHECK_FUNC(T) \
    static inline bool \
    PyStackRef_ ## T ## Check(_PyStackRef stackref) \
        if (PyStackRef_IsTaggedInt(stackref)) { \
            return false; \
        } \
        return Py ## T ## _Check(PyStackRef_AsPyObjectBorrow(stackref)); \
    }

...
STACKREF_CHECK_FUNC(Exception);
STACKREF_CHECK_FUNC(Code);
STACKREF_CHECK_FUNC(Function);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think it might not work when want to define variants of Check and CheckExact, though we can always define two macros for that if we go down this route.

Comment thread Lib/test/test_list.py
iterable doesn't prematurely free the iterable"""

def foo(x):
r = 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'd add this to make sure the test is testing what the comment is saying.
assert(sys.getrefcount(x) == 1)

Comment thread Python/stackrefs.c Outdated
_PyStackRef
PyStackRef_IncrementTaggedIntNoOverflow(_PyStackRef ref)
{
assert(ref.index != (uintptr_t)-1); // Overflow

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Do here same as in d9dc597 ?

markshannon merged commit f6f4e8a into python:main May 27, 2025
markshannon deleted the virtual-iterators branch May 27, 2025 14:59
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
* FOR_ITER now pushes either the iterator and NULL or leaves the iterable and pushes tagged zero

* NEXT_ITER uses the tagged int as the index into the sequence or, if TOS is NULL, iterates as before.
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
* FOR_ITER now pushes either the iterator and NULL or leaves the iterable and pushes tagged zero

* NEXT_ITER uses the tagged int as the index into the sequence or, if TOS is NULL, iterates as before.
gostak-dd pushed a commit to gostak-dd/cpython that referenced this pull request Jun 2, 2026
* FOR_ITER now pushes either the iterator and NULL or leaves the iterable and pushes tagged zero

* NEXT_ITER uses the tagged int as the index into the sequence or, if TOS is NULL, iterates as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL