Skip to content

Add iteration and standard impls in once crate #199

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

JoeyBF
Copy link
Collaborator

@JoeyBF JoeyBF commented Jul 21, 2025

It was getting annoying that MultiIndexed didn't implement Debug, Clone, PartialEq, Eq, Hash, since any structs that contain one would not be able to derive them. The main bottleneck was being able to iterate over the entire tree.

I implemented iterators and updated the criterion bench to make sure the performance is close to optimal. I also implemented all the standard traits for MultiIndexed, KdTrie, Grove and TwoSidedGrove. I added proptests to check for correctness too.

@JoeyBF
Copy link
Collaborator Author

JoeyBF commented Jul 22, 2025

For future reference, I did try unwrapping the new methods in benchable_impls.rs, so that the impl for Benchable<K, T> would call the method for Benchable<K-1, T> in a flat_map. This makes me very confused as the unwrapped version is significantly faster for large K (~3x), but also significantly slower for K = 2 (~4x). I'll leave the implementation as-is because I feel it's the most representative for uses outside of this crate.

Profiling the bad case with perf shows that the code is now spending most of its time executing the AVX2 instruction vmovups outside of the iterator. Interestingly, this is also the instruction that gives the bottleneck for the new iterators. With the naive nested loops, the bottleneck is now just the atomic load in WriteOnce.

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.

1 participant