Add prefetch for vector code - #5366
Conversation
|
Hi @markwwen! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
@mnorris11 has imported this pull request. If you are a Meta employee, you can view this in D111459405. |
|
Thanks for the contribution, will take a look cc @alexanderguzhva who added the prefetch parts just in case you are interested |
|
I wanted to ensure there is no regression on existing flows. I got a slight regression on GIST when testing just the 3 datasets below. This issued 1 query at a time in search() with |
|
Thanks for running these tests and for checking the existing flows. I reran SIFT1M after rebasing the change onto the current Configuration
Results
As a control for differences caused by the two parallel index builds, I also loaded the base-built index with both binaries. This made recall identical and still reduced TSC ticks per query by 12.0% to 14.6%, depending on These results are noticeably different from yours, both in speedup and in absolute recall. That suggests there is still an environment or benchmark configuration difference between the runs. In particular, CPU model, compiler/SIMD target, |
Summary
This PR adds an optional
DistanceComputer::prefetch(idx_t)hook and uses it in HNSW search to prefetch vector codes before distance computation.The default implementation is a no-op, so existing distance computers are unaffected.
NegativeDistanceComputerforwards the call to the wrapped distance computer, andFlatCodesDistanceComputerprefetches the first few cache lines of the target code.HNSW search now prefetches the next neighbor's vector code while iterating over neighbor candidates. This is intended to reduce memory access latency for flat-code-backed HNSW indexes without changing search results.
On sift-128-euclidean, this improves HNSW search QPS by 10% to 15% with no recall change.