Skip to content

Relax the 'static bound on DistanceComputer.#1007

Open
hildebrandmw wants to merge 3 commits intomainfrom
mhildebr/distance-computer-can-borrow
Open

Relax the 'static bound on DistanceComputer.#1007
hildebrandmw wants to merge 3 commits intomainfrom
mhildebr/distance-computer-can-borrow

Conversation

@hildebrandmw
Copy link
Copy Markdown
Contributor

@hildebrandmw hildebrandmw commented May 2, 2026

What

Remove the 'static bound on BuildDistanceComputer::DistanceComputer and allow the DistanceComputer associated type of PruneStrategy to have a lifetime.

Why

This bound is not really needed. Distance computers are almost exclusively used during prune loops, so there's no need for the 'static bound. Relaxing that bound allows DistanceComputer implementations to borrow from the associated provider. This is helpful for PQ since this allows DistanceComputers to borrow the central pivot table rather than requiring an Arc or some other reference counting mechanism.

Upgrade Guide

Since all current DistanceComputers are 'static, the only change needed is to add a lifetime to the DistanceComputer generic associated type of all PruneStrategy implementations.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to relax lifetime requirements around pruning distance computation so DistanceComputer implementations can borrow from their associated provider/accessor instead of being forced to be 'static.

Changes:

  • Removes the +'static bound from BuildDistanceComputer::DistanceComputer.
  • Refactors PruneStrategy::DistanceComputer into a lifetime-parameterized associated type (GAT) and wires it through PruneAccessor.
  • Updates in-repo PruneStrategy implementations to the new associated type shape.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
diskann/src/provider.rs Drops the 'static bound on BuildDistanceComputer::DistanceComputer.
diskann/src/graph/glue.rs Changes PruneStrategy::DistanceComputer to a GAT and connects it to PruneAccessor.
diskann/src/graph/test/provider.rs Updates the test prune strategy impl to the new DistanceComputer<'a> associated type.
diskann-providers/src/model/graph/provider/async_/inmem/test.rs Updates prune strategy test impl to new DistanceComputer<'a> associated type.
diskann-providers/src/model/graph/provider/async_/inmem/spherical.rs Updates prune strategy impl to new DistanceComputer<'a> associated type.
diskann-providers/src/model/graph/provider/async_/inmem/scalar.rs Updates prune strategy impl to new DistanceComputer<'a> associated type.
diskann-providers/src/model/graph/provider/async_/inmem/product.rs Updates prune strategy impls to new DistanceComputer<'a> associated type.
diskann-providers/src/model/graph/provider/async_/inmem/full_precision.rs Updates prune strategy impl to new DistanceComputer<'a> associated type.
diskann-providers/src/model/graph/provider/async_/caching/provider.rs Propagates the new DistanceComputer<'a> through the caching prune strategy wrapper.
diskann-providers/src/model/graph/provider/async_/bf_tree/provider.rs Updates bf-tree prune strategy impls to new DistanceComputer<'a> associated type.
diskann-garnet/src/provider.rs Updates Garnet prune strategy impl to new DistanceComputer<'a> associated type.
Comments suppressed due to low confidence (1)

diskann/src/graph/glue.rs:622

  • PruneStrategy::DistanceComputer<'computer> still has a + 'static bound. That prevents the associated DistanceComputer from borrowing from the provider/accessor, which is the main goal of this PR (and it also conflicts with the PR description). Consider removing the 'static bound here (and ensuring any call sites that truly need 'static add it locally instead).
    type DistanceComputer<'computer>: for<'a, 'b, 'c, 'd> DistanceFunction<
            <Self::PruneAccessor<'a> as Accessor>::ElementRef<'b>,
            <Self::PruneAccessor<'c> as Accessor>::ElementRef<'d>,
            f32,
        > + Send
        + Sync
        + 'static;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread diskann-providers/src/model/graph/provider/async_/inmem/test.rs Outdated
hildebrandmw and others added 2 commits May 2, 2026 12:08
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.49%. Comparing base (45428af) to head (3316411).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1007   +/-   ##
=======================================
  Coverage   89.49%   89.49%           
=======================================
  Files         448      448           
  Lines       84118    84118           
=======================================
  Hits        75282    75282           
  Misses       8836     8836           
Flag Coverage Δ
miri 89.49% <ø> (ø)
unittests 89.33% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
diskann-garnet/src/provider.rs 83.36% <ø> (ø)
...odel/graph/provider/async_/inmem/full_precision.rs 98.39% <ø> (ø)
...s/src/model/graph/provider/async_/inmem/product.rs 90.17% <ø> (ø)
...rs/src/model/graph/provider/async_/inmem/scalar.rs 92.78% <ø> (ø)
...src/model/graph/provider/async_/inmem/spherical.rs 88.13% <ø> (ø)
...ders/src/model/graph/provider/async_/inmem/test.rs 69.34% <ø> (ø)
diskann/src/graph/glue.rs 96.31% <ø> (ø)
diskann/src/graph/test/provider.rs 94.40% <ø> (ø)
diskann/src/provider.rs 95.14% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

4 participants