Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always use a Python iterator for sets and frozensets #3849

Merged
merged 2 commits into from
Feb 17, 2024

Conversation

davidhewitt
Copy link
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.

Copy link

codspeed-hq bot commented Feb 17, 2024

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

Copy link
Contributor

@LilyFoote LilyFoote left a comment

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
Member Author

Thanks for the review! 🙏

Merged via the queue into PyO3:main with commit eb90b81 Feb 17, 2024
37 of 39 checks passed
@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