Skip to content

fix(vector): restore wide float32 L2 throughput - #29194

Closed
Lundomn wants to merge 1 commit into
matrixorigin:mainfrom
Lundomn:codex/issue-29183-fix
Closed

Lundomn wants to merge 1 commit into
matrixorigin:mainfrom
Lundomn:codex/issue-29183-fix

Conversation

@Lundomn

@Lundomn Lundomn commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #29183

What this PR does / why we need it:

Fixes #29183, an IVFFLAT 10M-row CREATE INDEX performance regression introduced after #29143.

Root cause

#29143 correctly widened float32 brute-force results to float64 to preserve #29083 extreme-value correctness. However, normal float32 L2 distances were then routed through StableL2DistanceSq, whose per-call scale/NaN/Inf scan became the dominant CPU cost during IVFFLAT centroid assignment. The #29183 profile shows this exact path.

Fix and behavior

Keep float64 accumulation and ordering, but use a dedicated finite float32 -> float64 squared-L2 kernel that converts operands before subtraction and accumulates in one pass with no allocations. For non-finite input or an unexpected non-finite accumulator, it falls back to StableL2DistanceSq to preserve existing NaN/Inf semantics. The fast path is used for both L2 metric enum variants in the wide float32 resolver; unrelated metrics and narrow-result paths are unchanged.

Regression coverage includes extreme values, subnormals, precision/order preservation, NaN/Inf semantics, dimension mismatch, resolver dispatch, and both Search and SearchFloat32 brute-force consumers.

Validation

  • GOWORK=off go test -mod=readonly ... ./pkg/vectorindex/metric — passed.
  • GOWORK=off go test -mod=readonly ... ./pkg/vectorindex/brute_force — passed.
  • GOWORK=off go vet -mod=readonly ... ./pkg/vectorindex/metric ./pkg/vectorindex/brute_force — passed.
  • 768-dimensional benchmark: 0 allocations; the new kernel measured 287.5–341.6 ns/op and the stable kernel 2304–2886 ns/op on Apple M1 across three runs.

The local repository CGo wrapper could not build a fresh native dependency set because the ONNX Runtime download timed out. The package tests above used the generated third-party headers/libs and a previously built compatible native libmo; the resulting linker duplicate-library/rpath warnings were non-fatal. A 10M-row TKE run remains required to verify end-to-end CREATE INDEX wall time and ISCP timeout behavior in the target deployment environment. At PR creation, CI preflight and coverage eligibility passed; Linux build/UT/SCA/coverage and Mergify checks were still queued or running.

Compatibility and performance risk

The change is isolated to wide float32 L2 distance dispatch and preserves a stable fallback for non-finite inputs. The new helper is build-tag independent and allocation-free; amd64/SIMD and target-cluster validation are covered by CI/TKE rather than the local Apple arm64 host.

Final head: 74b6b420ac5693e589da8e356753300e4fe488bc.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@cpegeric cpegeric left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will handle this bug.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 10M IVFFLAT CREATE INDEX stalls in mapping with repeated ISCP transaction finish timeouts

3 participants