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

feat: Implement optimized TreeMap iterator functions #428

Merged
merged 14 commits into from
Jun 22, 2021

Conversation

austinabell
Copy link
Contributor

Closes #426

This PR just makes the implementation more efficient, to avoid unnecessary storage reads

This should be functionally the same externally, but since it will reduce storage reads it's a breaking change in a smart contract context

@austinabell austinabell force-pushed the austin/tree_map/iter_update branch from a810239 to 4e06609 Compare May 26, 2021 19:58
@matklad
Copy link
Contributor

matklad commented May 27, 2021

Probably makes sense to add some smoke tests here. There was a funny bug in std when a combination of nth and rev flat out gave wrong results in some cases, and nobody noticed )

@matklad
Copy link
Contributor

matklad commented Jun 10, 2021

Probably makes sense to add some smoke tests here.

not related to the PR per-se, but it'd be cool to look into setting up property-based/fuzz testing for collections. std collections give us a good, free oracle we can compare against. The two relevant crates in the rust ecosystem are (from most important to least importat)

Which reminds me that I should dig into https://github.com/graydon/photesthesis at some point...

@austinabell
Copy link
Contributor Author

austinabell commented Jun 10, 2021

Probably makes sense to add some smoke tests here.

not related to the PR per-se, but it'd be cool to look into setting up property-based/fuzz testing for collections. std collections give us a good, free oracle we can compare against. The two relevant crates in the rust ecosystem are (from most important to least importat)

Which reminds me that I should dig into graydon/photesthesis at some point...

Yeah, I added some basic tests, but yeah fuzzing probably is out of the scope of this. I'd love to tackle this when I have time.

I assume when you mention arbitrary you mean to be used with cargo-fuzz? quickcheck is already used in the SDK for treemap tests, so it is probably the least cost to add those to be run as tests, but definitely would be nice to extensively fuzz all data structures and interactions.

@matklad
Copy link
Contributor

matklad commented Jun 10, 2021

I assume when you mention arbitrary you mean to be used with cargo-fuzz?

Not necessary -- I believe that the arbitrary crate is setup in such a way that is useful even without coverage-guided fuzzers, so it should be possible to use it the same way quickcheck is used, via simple #[test]. I don't think the ecosystem is quite there yet, so it might be that we'll have to do some ground-work here ourselves. arbitrary does seem to be a very well-designed crate that captures the essense of randomized testing, so I'd like to find a way to marry convenient tests with it.

@austinabell
Copy link
Contributor Author

austinabell commented Jun 10, 2021

Not necessary -- I believe that the arbitrary crate is setup in such a way that is useful even without coverage-guided fuzzers, so it should be possible to use it the same way quickcheck is used, via simple #[test]. I don't think the ecosystem is quite there yet, so it might be that we'll have to do some ground-work here ourselves. arbitrary does seem to be a very well-designed crate that captures the essense of randomized testing, so I'd like to find a way to marry convenient tests with it.

And the benefit of doing this over using quickcheck? More control?

Edit: Also just to check, do you think anything in this test should change wrt these points?

@austinabell austinabell requested a review from matklad June 10, 2021 15:49
@matklad
Copy link
Contributor

matklad commented Jun 10, 2021

And the benefit of doing this over using quickcheck? More control?

The arbitrary crate is a good ecosystem-wide interface. I expect that, over time, a lot of other crates would implement arbitrary::Arbitrary. So, if we make our stuff Adbitrary, then we'll be more inter-operable.

That's I am betting on arbitrary: it's a 1.0 crate which defines just the narrow interface for randomization, without being opinionated about how actual property testing is commenced.

@austinabell
Copy link
Contributor Author

The arbitrary crate is a good ecosystem-wide interface. I expect that, over time, a lot of other crates would implement arbitrary::Arbitrary. So, if we make our stuff Adbitrary, then we'll be more inter-operable.

That's I am betting on arbitrary: it's a 1.0 crate which defines just the narrow interface for randomization, without being opinionated about how actual property testing is commenced.

You okay with this being done in a separate PR? I can create an issue later.

Rather not increase the scope of this PR if possible

@matklad
Copy link
Contributor

matklad commented Jun 18, 2021

You okay with this being done in a separate PR? I can create an issue later.

Sure, I am always for splitting up PR, and for non-blocking PRs!

@mikedotexe mikedotexe merged commit 4b59bfd into master Jun 22, 2021
@mikedotexe mikedotexe deleted the austin/tree_map/iter_update branch June 22, 2021 14:03
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.

Extend TreeMap iterator implementation
4 participants