advisedy opened a new pull request, #3562:
URL: https://github.com/apache/kvrocks/pull/3562

   Fixes #2398.
   
   
   ### Problem
   
   `HnswIndex` currently owns a `std::mt19937` generator directly, so every
   `HnswIndex` construction also constructs the random generator.
   
   However, the generator is only needed by `RandomizeLayer()` when inserting
   vector entries. `HnswIndex` can also be constructed on query paths such as
   KNN/RANGE search, where random layer generation is not used.
   
   
   ### Fix
   
   - Replace the eager `std::mt19937` member with a lazily initialized
     `std::unique_ptr<std::mt19937>`.
   - Initialize the generator only on the first `RandomizeLayer()` call.
   
   ### Tests
   
   new C++ gtests added (hnsw_index_test.cc):
   
   - `RandomGeneratorIsInitializedLazily`
   
   ### AI-assisted contribution
   
   I used an LLM to help draft the new GTest case for verifying lazy generator
   initialization. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to