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

VisitedList: Vec<usize> -> Vec<u8> #5336

Merged
merged 3 commits into from
Oct 31, 2024
Merged

VisitedList: Vec<usize> -> Vec<u8> #5336

merged 3 commits into from
Oct 31, 2024

Conversation

xzfc
Copy link
Contributor

@xzfc xzfc commented Oct 30, 2024

This PR optimizes VisitedList by switching counters from usize to u8 (and memset them every 256 iterations). Surprisingly, this change improves not only the memory usage, but also the search/build performance.

$ cargo bench -p segment --bench hnsw_search_graph # old
hnsw-index-search-group/hnsw_search
                        time:   [634.32 µs 640.56 µs 646.44 µs]


$ cargo bench -p segment --bench hnsw_search_graph # new
hnsw-index-search-group/hnsw_search
                        time:   [596.08 µs 601.57 µs 606.93 µs]

Large graphs are also improved. Graph build time (dim=4, npoints=10_000_000): 892s → 640s.

@xzfc xzfc requested review from generall and IvanPleshkov October 30, 2024 07:08
@generall
Copy link
Member

Benchmark on deep-image-96-angular (10M 96d vectors + sq) confirms ~10% improvement

image

@generall generall merged commit 59c2ded into dev Oct 31, 2024
18 checks passed
@generall generall deleted the opt-visited-u8 branch October 31, 2024 17:26
n0x29a pushed a commit that referenced this pull request Nov 4, 2024
* Do not use VisitedListHandle::count_visits_since()

* VisitedList: use u8 instead of usize

* Test VisitedList
@xzfc xzfc mentioned this pull request Nov 5, 2024
timvisee pushed a commit that referenced this pull request Nov 8, 2024
* Do not use VisitedListHandle::count_visits_since()

* VisitedList: use u8 instead of usize

* Test VisitedList
@timvisee timvisee mentioned this pull request Nov 8, 2024
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