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

Implement set iterators in terms of limited API #1167

Merged
merged 1 commit into from
Sep 9, 2020

Conversation

alex
Copy link
Contributor

@alex alex commented Sep 8, 2020

No description provided.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

As this looks like it could have performance drawbacks, can we perhaps consider in this case having two implementations depending on the API available?

Or at least a benchmark showing that the difference is not meaningful.

(We have some benchmarks for iterating list and dict so should be able to duplicate them easily for set.)

@alex
Copy link
Contributor Author

alex commented Sep 8, 2020

I'll do a PR adding the benchmark to master, then we compare performance between teh two.

@alex
Copy link
Contributor Author

alex commented Sep 8, 2020

Are there instructions on running benchmarks?

@davidhewitt
Copy link
Member

cargo +nightly bench should do it - though great point, should add this to contributing.md

@alex
Copy link
Contributor Author

alex commented Sep 8, 2020

The measurements are a bit noisy, because I'm running on a laptop, but bench_set from #1168 is 10-15% slower. Is that so much of a slowdown that it needs 2x the impls? My instinct is that it's not worth it unless someone has a specific use case.

@kngwyu
Copy link
Member

kngwyu commented Sep 9, 2020

How about making the current set iterator #[cfg(not(Py_LIMITED_API))]? (EDITED: I noticed that it is already not(Py_LIMTED_API)
We can do the same thing by PyIterator::from_object as the new implementation and isn't it insufficient?

@davidhewitt
Copy link
Member

+1 - I think that as we've already got both implementations written, and a single test will cover both APIs depending on the features, it's easy for us to support both.

10-15% may not be huge, but for some people the choice of Rust is for everything to be as fast as possible, so they will still appreciate this.

@alex alex force-pushed the abi3-sets branch 2 times, most recently from 8fdeeee to d8f7869 Compare September 9, 2020 11:47
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM!

@davidhewitt davidhewitt merged commit 0bc2393 into PyO3:abi3 Sep 9, 2020
@alex alex deleted the abi3-sets branch September 9, 2020 12:06
@kngwyu
Copy link
Member

kngwyu commented Sep 9, 2020

I meant 'probably we don't need PySetIterator for #[cfg(Py_LIMITED_API)]'.

@alex
Copy link
Contributor Author

alex commented Sep 9, 2020

@kngwyu we do -- it needs to PyIterator is an iterator of PyResult, not an iterator of PyAny. You need PySetIterator to unwrap the PyResult (which is fine because in reality PySet's iterator can never error).

@kngwyu
Copy link
Member

kngwyu commented Sep 9, 2020

OK, that makes sense.

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.

3 participants