-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Fix memory bloat in IndexBinaryHash search due to argument copying in dispatch_HammingComputer #4600
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
Conversation
… dispatch_HammingComputer
|
Hi @tracywong117! 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 [email protected]. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
@tracywong117 great, thanks! If you believe that there will be no side effects from this change, then please feel free to replace the original dispatch version with a new one without creating an additional facility |
|
Hi @tracywong117 |
|
Thanks for the feedback! I'll update the PR to use pointers instead of perfect forwarding. Will push the changes shortly. |
|
@tracywong117 It is an awesome fix! Thank for making the change! Would you mind fixing the format issue so we could merge the code? Thank! |
… dispatch_HammingComputer (facebookresearch#4600) Summary: Fixes excessive memory usage (3x index size) in IndexBinaryHash search operations caused by pass-by-value semantics in variadic template dispatch. ## Problem When searching a 114GB IndexBinaryHash index, RAM usage peaked at ~342GB (3x index size) due to argument copying in the template dispatch mechanism: - `dispatch_HammingComputer` uses `Types... args` (pass-by-value) - `Run_search_single_query::f` uses `Types... args` (pass-by-value) - This causes all arguments to be copied at each template instantiation ## Solution 1. **Added `dispatch_HammingComputer_perfect_forward`** in `utils/hamming_distance/hamdis-inl.h`: New function using perfect forwarding of arguments 2. **Fixed `Run_search_single_query`** in `IndexBinaryHash.cpp`: Changed to use perfect forwarding ## Testing - Tested with 114GB IndexBinaryHash index - RAM usage reduced from ~342GB to ~114GB (expected size) - Search results remain identical - No performance regression observed ## Backward Compatibility - Original `dispatch_HammingComputer` remains unchanged - No breaking changes to public API Pull Request resolved: facebookresearch#4600 Reviewed By: mnorris11 Differential Revision: D84538582 Pulled By: junjieqi fbshipit-source-id: 2e63e3b2ff3e8b37f7ffe919801d93bf941c3533
Summary
Fix excessive memory usage (3x index size) in IndexBinaryHash search operations caused by pass-by-value semantics in variadic template dispatch.
Problem
When searching a 114GB IndexBinaryHash index, RAM usage peaked at ~342GB.
Root cause:
This caused arguments to be copied for each instantiation, inflating memory usage.
Solution
Testing
Backward Compatibility