fuzzy: Move segment results instead of cloning them (#66982)

## Summary

The string and path-set matchers in `fuzzy` and `fuzzy_nucleo` collect
matches per segment. They merged the segments with
`segment_results.concat()`, which clones every element. Each match was
copied (a `String` and a `Vec` for `fuzzy::StringMatch`) and the
original dropped, before the results were truncated to `max_results`.
This moves the matches.

`cargo bench -p fuzzy_nucleo --bench match_benchmark`, string matching
with 1-word queries:

| Benchmark | Before | After |
|---|---|---|
| `1-word/fuzzy/1000` | 67.9 µs | 58.4 µs |
| `1-word/fuzzy/10000` | 532 µs | 444 µs |
| `1-word/nucleo/1000` | 67.2 µs | 62.0 µs |
| `1-word/nucleo/10000` | 472 µs | 406 µs |

The 2- and 4-word groups match fewer candidates and improved by 2% to
22%. The path groups in that benchmark use `match_fixed_path_set`, which
this does not change.

A copy of the merge step outside Zed, merging 10,000 `StringMatch`
values from 16 segments: 412 µs before, 75 µs after.

## Testing

`cargo test -p fuzzy --features path/test-support`, `cargo test -p
fuzzy_nucleo`, and `cargo test -p file_finder --lib` pass.

## Self-review

- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.

Release Notes:

- Improved fuzzy matching performance when many candidates match
This commit is contained in:
Parker Loflin
2026-11-15 09:13:12 +00:00
committed by GitHub
parent fb62376caa
commit 5f27a0a02a
4 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -255,7 +255,7 @@ pub async fn match_path_sets<'a, Set: PathMatchCandidateSet<'a>>(
return Vec::new();
}
let mut results = segment_results.concat();
let mut results = segment_results.into_iter().flatten().collect::<Vec<_>>();
gpui_util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a));
results
}
+1 -1
View File
@@ -194,7 +194,7 @@ where
return Vec::new();
}
let mut results = segment_results.concat();
let mut results = segment_results.into_iter().flatten().collect::<Vec<_>>();
rank_matches(&mut results, max_results);
results
}
+1 -1
View File
@@ -400,7 +400,7 @@ pub async fn match_path_sets<'a, Set: PathMatchCandidateSet<'a>>(
return Vec::new();
}
let mut results = segment_results.concat();
let mut results = segment_results.into_iter().flatten().collect::<Vec<_>>();
gpui_util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a));
results
}
+1 -1
View File
@@ -190,7 +190,7 @@ where
return Vec::new();
}
let mut results = segment_results.concat();
let mut results = segment_results.into_iter().flatten().collect::<Vec<_>>();
gpui_util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a));
results
}