Skip to content

fix(python): parallelize small high-dimensional query/add batches - #671

Open
chakshu-dhannawat wants to merge 1 commit into
nmslib:masterfrom
chakshu-dhannawat:fix/threading-small-batch-high-dim
Open

fix(python): parallelize small high-dimensional query/add batches#671
chakshu-dhannawat wants to merge 1 commit into
nmslib:masterfrom
chakshu-dhannawat:fix/threading-small-batch-high-dim

Conversation

@chakshu-dhannawat

Copy link
Copy Markdown

Closes #667.

The current Python bindings disabled multithreading whenever the input batch was smaller than 4 * num_threads, regardless of vector dimension. For high-dimensional vectors the per-query work is large enough that serial execution wastes cores.

This change replaces the rows-only threshold with a total-scalar-work threshold (rows * dim). It keeps the existing serialization behavior for low-dimensional vectors while letting small high-dimensional batches use multiple threads.

Changes:

  • Use rows * dim to decide whether to fall back to a single thread in both addItems and knn_query.
  • Add bindings_test_small_batch_threading.py, a regression test that verifies parallel knn_query is measurably faster than serial for a small, high-dimensional batch.

Tested: python -m unittest discover --start-directory tests/python --pattern "bindings_test*.py" => 15 tests passed.

The rows-only threshold disabled multithreading whenever the batch size was below 4 * num_threads, ignoring vector dimension. For high-dimensional vectors, even a small batch has enough per-vector work to benefit from threads.

Switch the heuristic to total scalar work (rows * dim). This preserves the existing serialization behavior for low-dimensional vectors while allowing high-dimensional queries/adds to use multiple threads.

Closes nmslib#667.

Signed-off-by: Awsheshmac <sharuma.aushieshu@otsuka-shokai.co.jp>
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.

Multithreading is disabled for small batches what slows down high-dimensional queries (Python bindings)

2 participants