Skip to content

perf(diskann): reduce peak memory usage during index build and merge - #762

Open
iaojnh wants to merge 5 commits into
alibaba:mainfrom
iaojnh:fix/merge-memory-used
Open

iaojnh wants to merge 5 commits into
alibaba:mainfrom
iaojnh:fix/merge-memory-used

Conversation

@iaojnh

@iaojnh iaojnh commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Reduce peak RSS during DiskANN index construction by avoiding redundant vector copies and releasing build buffers earlier. Apply the build lifecycle and streaming merge approach introduced for IVF in #733.

Changes

  • Stream merged inputs directly instead of materializing a complete merged vector holder.
  • Replace the copied PQ training prefix with a lightweight view, and copy only selected training vectors while preserving the existing sampling order.
  • Bound PQ encoding batches to a 4 MiB target and release graph vectors before encoding.
  • Release the completed builder before opening the persisted index, then free input holders, converters, and cached vectors after success.
  • Preserve retry behavior after dump or open failures, and propagate deferred source read errors during streaming dumps.

Validation

Linux ARM64, GCC 13.3, Release build:

  • 112 tests passed, with 2 architecture-specific skips.
  • Covered direct and merged builds across FP32/FP16 and L2/Cosine, resource cleanup, dump/open retries, deferred read failures, and repeated dumps.
  • Verified that streaming PQ sampling produces the same sample bytes and order as the previous implementation.

Peak RSS

Measured against baseline 70f12576 using 20,000 vectors with 768 dimensions, 4 threads, graph degree 32, build list size 50, and 48 PQ chunks.

Build Before After Reduction
Direct FP32 419.0 MiB 239.4 MiB 42.9%
Direct FP16 293.7 MiB 203.9 MiB 30.6%
Merge FP32 401.9 MiB 161.9 MiB 59.7%
Merge FP16 275.7 MiB 125.6 MiB 54.4%

Direct FP32 values are medians of three runs per version; other cases use one run per version. Peak RSS includes input preparation, construction, dumping, and opening the index. All 12 builds passed document-count and sampled-vector checks.

These synthetic measurements establish RSS savings for the tested workload. Limited query coverage and substantial timing variation do not establish recall or build-time equivalence.

@iaojnh iaojnh changed the title Fix/merge memory used perf(diskann): reduce peak memory usage during index build and merge Sep 16, 2026
Reduce construction RSS by streaming merged inputs, copying only selected
PQ training vectors, and releasing completed build buffers earlier.

Use a prefix view to preserve the existing PQ training population and
sampling order. Bound encoding batches to a 4 MiB target and release graph
vectors before encoding.

Apply the IVF build lifecycle to DiskANN: release the completed builder
before opening the persisted index, retain retryable state after failures,
and free input holders, converters, and cached vectors after success.
Propagate deferred source read failures during streaming dumps.

Add regression coverage for FP32/FP16 and L2/Cosine builds, resource cleanup,
dump/open retries, deferred read failures, and legacy PQ sample order.

Validation on Linux ARM64: 112 tests passed, with 2 architecture-specific
skips. Peak RSS decreased by 30.6-59.7% across direct and merged FP32/FP16
builds in the 20,000 x 768 synthetic workload. Direct FP32 uses the median
of three runs per version; other cases use one run per version.
iaojnh and others added 4 commits September 16, 2026 21:02
Preserve DiskANN build-state and memory-release behavior while adopting main's method naming. Update the regression test initialization call to the renamed API.
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