Improve vector search speed by using FixedBitSet #12789
Closed
+5
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While doing some performance testing and digging into flamegraphs, I noticed for smaller vectors (96dim float32), we were losing a fair bit of time within the
SparseFixedBitSet#getAndSet
method.I am assuming we are using
SparseFixedBitSet
for performance reasons to reduce memory usage?I ran some tests with topK=100 and fanOut=1000. To check memory usage, in a separate run, I printed out
bitSet.ramBytesUsed()
after every search.I tested using FixedBitSet instead with GLOVE and saw almost a 10% improvement in search speed:
Vs. baseline
The total ramBytesUsed (allocated and then gc'd collected) for 1000 searches over glove was
21288656
bytes. For fixed bit set, every search only allocates12544
, which pans out to12544000
bytes (actually less than sparse).To confirm this was still true for larger vectors and a larger graph, I tested against 400k cohere vectors (same params). There is a bit more noise in the measurements, so I averaged the latency over 4 runs:
candidate:
6.115
with a min:5.96
baseline:
6.23
with a min:6.15
.Total memory usage for sparse:
103982464
vs for total memory usage for Fixed50040000
Do we know the goal for using a SparseFixedBitSet and under what conditions it would actually perform better than a regular FixedBitSet? I will happily test some more.