Skip to content

always use a Python iterator for sets and frozensets - #3849

Merged
davidhewitt merged 2 commits into
PyO3:mainfrom
davidhewitt:set-iteration
Feb 17, 2024
Merged

davidhewitt merged 2 commits into
PyO3:mainfrom
davidhewitt:set-iteration

Conversation

@davidhewitt

Copy link
Copy Markdown
Member

Related to #3762

This removes the branching of Py_LIMITED_API / not(Py_LIMITED_API) code for iterators of set and frozenset, opting to just use the Py_LIMITED_API forms in all cases.

This is slightly slower but recommended for stability due to use of private API _PySet_NextEntry which might also not work properly when iterating set subclasses (if they override iteration).

At the same time I added ExactSizeIterator implementations to both iterators, as we had that previously just for the not(Py_LIMITED_API) case.

Overall this is a code simplification and consistency improvement.

@codspeed

codspeed Bot commented Feb 17, 2024 •

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #3849 will degrade performances by 15.63%

Comparing davidhewitt:set-iteration (11bc256) with main (940804f)

Summary

⚡ 1 improvements
❌ 3 regressions
✅ 75 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main davidhewitt:set-iteration Change
❌ mapping_from_dict 300 ns 355.6 ns -15.63%
⚡ f64_from_pyobject 516.7 ns 461.1 ns +12.05%
❌ sequence_from_list 300 ns 355.6 ns -15.63%
❌ sequence_from_tuple 232.8 ns 260.6 ns -10.66%

@davidhewitt

Copy link
Copy Markdown
Member Author

At least on codspeed, ignoring the usual volatile benchmarks we see reported here, the benchmarks basically show no difference for removing the "fast" path, so I think this increases the justification for doing this.

image

@LilyFirefly LilyFirefly left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems straightforward to me.

@davidhewitt
davidhewitt added this pull request to the merge queue Feb 17, 2024
@davidhewitt

Copy link
Copy Markdown
Member Author

Thanks for the review! 🙏

Merged via the queue into PyO3:main with commit eb90b81 Feb 17, 2024
@davidhewitt
davidhewitt deleted the set-iteration branch February 17, 2024 11:46
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