pyo3 icon indicating copy to clipboard operation
pyo3 copied to clipboard

use `PyIter_NextItem` during iteration

Open davidhewitt opened this issue 1 month ago • 2 comments

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

davidhewitt avatar Nov 29 '25 15:11 davidhewitt

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 avatar Nov 30 '25 10:11 davidhewitt

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

image

davidhewitt avatar Nov 30 '25 10:11 davidhewitt