Skip to content

Conversation

@markshannon
Copy link
Member

@markshannonmarkshannon commented Apr 15, 2025

Just a draft PR until I have performance numbers.

@markshannon
Copy link
MemberAuthor

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

Stats show no significant changes

@Fidget-Spinner
Copy link
Member

@markshannon I don't think it matters here, but you didn't update in https://github.com/python/cpython/pull/132545/filesPy_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.

@markshannon
Copy link
MemberAuthor

@markshannon I don't think it matters here, but you didn't update in https://github.com/python/cpython/pull/132545/filesPy_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

staticinline_PyStackRef
PyStackRef_IncrementTaggedIntNoOverflow(_PyStackRefref)
{
assert(ref.bits!= (uintptr_t)-1); // Deosn't overflow
Copy link
Member

Choose a reason for hiding this comment

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

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

return false;
}
returnPyFunction_Check(PyStackRef_AsPyObjectBorrow(stackref));
}
Copy link
Member

Choose a reason for hiding this comment

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

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); 

Choose a reason for hiding this comment

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

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.

iterable doesn't prematurely free the iterable"""

deffoo(x):
r=0
Copy link
Member

Choose a reason for hiding this comment

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

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

_PyStackRef
PyStackRef_IncrementTaggedIntNoOverflow(_PyStackRefref)
{
assert(ref.index!= (uintptr_t)-1); // Overflow
Copy link
Member

Choose a reason for hiding this comment

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

Do here same as in d9dc597 ?

@markshannonmarkshannon merged commit f6f4e8a into python:mainMay 27, 2025
72 checks passed
@markshannonmarkshannon 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.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@markshannon@Fidget-Spinner@iritkatriel