Skip to content

fix: Replace std::vector with std::array for distance impl#201

Merged
iaojnh merged 4 commits intomainfrom
fix/vector-to-array
Mar 7, 2026
Merged

fix: Replace std::vector with std::array for distance impl#201
iaojnh merged 4 commits intomainfrom
fix/vector-to-array

Conversation

@iaojnh
Copy link
Collaborator

@iaojnh iaojnh commented Mar 6, 2026

No description provided.

@greptile-apps
Copy link

greptile-apps bot commented Mar 6, 2026

Greptile Summary

This PR replaces std::vector with std::array for all fixed-size local buffers in distance computation hot paths across five files (lloyd_cluster.h, mips_euclidean_distance_matrix.h, and the three inner_product_distance_batch_impl* variants). Since every array size is a compile-time template parameter (BatchCount, M, N, dp_batch), the substitution is valid.

Key observations:

  • All converted arrays are properly initialized before use: via std::fill, SIMD setzero intrinsics, or element-wise assignment in loops
  • Heap allocations inside SIMD hot loops are correctly eliminated, delivering a measurable performance improvement
  • No remaining uses of std::vector or #include <vector> in active code paths
  • The commented-out avx512bw fallback (explicitly marked "TODO: this version is problematic") contains issues but is deferred work

This PR is safe to merge; all active code is correct and the change is a net performance win.

Confidence Score: 5/5

  • All active code paths correctly initialize and use stack-allocated arrays; this is a safe performance improvement.
  • All array substitutions are verified correct: compile-time sizes, proper initialization before use, no uninitialized-read paths in active code. Heap allocations are correctly eliminated from hot SIMD loops. The only code with latent issues is explicitly commented-out and already flagged by the author as deferred work.
  • No files require special attention

Last reviewed commit: ed3e923

@iaojnh
Copy link
Collaborator Author

iaojnh commented Mar 7, 2026

@greptile

@iaojnh iaojnh merged commit cfbd3ca into main Mar 7, 2026
10 checks passed
@iaojnh iaojnh deleted the fix/vector-to-array branch March 7, 2026 09:49
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.

2 participants