Skip to content

use PyIter_NextItem during iteration#5661

Merged
bschoenmaeckers merged 5 commits intoPyO3:mainfrom
davidhewitt:pyiter-nextitem
Jan 13, 2026
Merged

use PyIter_NextItem during iteration#5661
bschoenmaeckers merged 5 commits intoPyO3:mainfrom
davidhewitt:pyiter-nextitem

Conversation

@davidhewitt
Copy link
Copy Markdown
Member

Possibly more interesting after #5660 which will show if there is any benchmark improvement here :)

@davidhewitt
Copy link
Copy Markdown
Member Author

Seems like there is a minor performance loss in (e.g.) set iteration. Looks like the set iterator has a remaining variable, I think we don't need that overhead because PyObject_LengthHint returns the correct thing for a set iterator. I'll try to adjust later.

@davidhewitt
Copy link
Copy Markdown
Member Author

For generic iterators, this does seem to be slightly faster:

image

@davidhewitt davidhewitt marked this pull request as ready for review January 13, 2026 19:24
Copy link
Copy Markdown
Member

@bschoenmaeckers bschoenmaeckers left a comment

Choose a reason for hiding this comment

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

LGTM!

@bschoenmaeckers bschoenmaeckers added this pull request to the merge queue Jan 13, 2026
Merged via the queue into PyO3:main with commit 95fd08e Jan 13, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants