Skip to content

refactor: remove dead code and redundant state in HNSW, IVF and dispatch - #186

Merged
gouyt13 merged 3 commits into
mainfrom
refactor/remove-dead-state
Oct 30, 2026
Merged

gouyt13 merged 3 commits into
mainfrom
refactor/remove-dead-state

Conversation

@gouyt13

@gouyt13 gouyt13 commented Oct 30, 2026

Copy link
Copy Markdown
Member

Summary

Remove dead code and redundant state. The removed code either has no callers or can never trigger, so behavior is unchanged. No public API, Python API or saved-index format changes. The private layout of HierarchicalNSW changes; its source API does not.

  • HNSW
    • Remove label_op_locks_: 65536 mutexes allocated on every construct and load that protected nothing. add_point is only called by construct, which passes distinct labels within its validated capacity.
    • Turn the duplicate-label and capacity throws in add_point into asserts, since construct already guarantees both.
    • Replace four graph-traversal candidate guards with assert(cand < num_stored_points_). The guards had diverged (> max_elements_ vs. >= num_stored_points_) and could not fire: construct and add publish IDs before linking, and load validates every neighbor.
    • Remove two first-element else branches whose stores were always overwritten by the promotion that follows.
  • IVF
    • Reduce the five readiness checks to !ready_; the error messages are unchanged. ready_ is set only after construct or load creates the initializer, rotator and cluster storage, and reserve already omitted two of the extra conditions.
    • Assert the internal cluster-size invariant in quantize_cluster.
    • Drop the unreachable metric branch in search; the metric is validated on construction and load.
  • Dispatch / core / clustering
    • Remove the unused RABITQ_RESOLVE2 macro and the two-argument resolve_kernel.
    • Fold the single-use src/simd/excode_dispatch.hpp into dispatch.cpp with internal linkage.
    • Remove the test-only one_bit::one_bit_code. The sign-convention test now uses one_bit_code_with_factor, which is the function production code calls.
    • Drop two static_cast<void>(num_workers) in LloydKMeans where the variable is also used outside OpenMP pragmas.

Kept on purpose:

  • hnsw::detail::search_knn: a documented compatibility adapter and an exported symbol.
  • The remaining two num_workers casts: those variables appear only in pragmas, so the casts prevent unused-variable warnings when pragmas are ignored.

Testing

  • Full portable CTest (RABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF, --no-tests=error) on an AVX-512 Linux host:
    • Release: 410 passed, 1 skipped.
    • ASan/UBSan Debug, with the new asserts enabled: 410 passed, 1 skipped.
    • The skipped test is the placement test, which requires OpenMP binding.
  • check-format.sh, full check-tidy.sh build-tidy and git diff --check passed.
  • No test, binding or doc references the removed error messages.
  • No new compiler warnings.
  • Not run locally: NEON, Windows, macOS and OpenMP-off core builds.

add_point is only called by construct, which passes distinct labels within its validated capacity, so the 65536 per-label mutexes protected nothing and the duplicate-label and capacity throws could not fire. Graph traversal guards had diverged (> max_elements_ vs >= num_stored_points_) and were unreachable because construct and add publish IDs before linking and load validates every neighbor; assert the invariant instead. Remove the first-element else branches, whose stores were always overwritten by the promotion that follows.
ready_ is set only after construct or load has created the initializer, rotator and cluster storage, so the extra conditions in the five readiness checks were redundant; reserve already omitted two of them. Messages are unchanged. Assert the internal cluster-size invariant and drop the unreachable metric branch in search; the metric is validated on construction and load.
Remove the unused RABITQ_RESOLVE2 macro and two-argument resolve_kernel, fold the single-use excode_dispatch.hpp into dispatch.cpp with internal linkage, remove the test-only one_bit_code in favor of one_bit_code_with_factor, and drop two redundant void casts in LloydKMeans.
@github-actions github-actions Bot added the release:maintenance Release category managed from the PR title label Oct 30, 2026
@gouyt13
gouyt13 merged commit be746e6 into main Oct 30, 2026
49 checks passed
@gouyt13
gouyt13 deleted the refactor/remove-dead-state branch October 30, 2026 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:maintenance Release category managed from the PR title

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant