From 5f27a0a02ab0f66755a15871b55f2cd8069325e0 Mon Sep 17 00:00:00 2001 From: Parker Loflin Date: Sun, 15 Nov 2026 09:13:12 +0000 Subject: [PATCH] fuzzy: Move segment results instead of cloning them (#66982) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 --- crates/fuzzy/src/paths.rs | 2 +- crates/fuzzy/src/strings.rs | 2 +- crates/fuzzy_nucleo/src/paths.rs | 2 +- crates/fuzzy_nucleo/src/strings.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fuzzy/src/paths.rs b/crates/fuzzy/src/paths.rs index e16639f9e13..81ecbdadead 100644 --- a/crates/fuzzy/src/paths.rs +++ b/crates/fuzzy/src/paths.rs @@ -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::>(); gpui_util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a)); results } diff --git a/crates/fuzzy/src/strings.rs b/crates/fuzzy/src/strings.rs index b48c1d7ffc9..2bc80bf0847 100644 --- a/crates/fuzzy/src/strings.rs +++ b/crates/fuzzy/src/strings.rs @@ -194,7 +194,7 @@ where return Vec::new(); } - let mut results = segment_results.concat(); + let mut results = segment_results.into_iter().flatten().collect::>(); rank_matches(&mut results, max_results); results } diff --git a/crates/fuzzy_nucleo/src/paths.rs b/crates/fuzzy_nucleo/src/paths.rs index 71d8c702380..a026538fe85 100644 --- a/crates/fuzzy_nucleo/src/paths.rs +++ b/crates/fuzzy_nucleo/src/paths.rs @@ -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::>(); gpui_util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a)); results } diff --git a/crates/fuzzy_nucleo/src/strings.rs b/crates/fuzzy_nucleo/src/strings.rs index 99f1b6d5f0e..bc43085a0a2 100644 --- a/crates/fuzzy_nucleo/src/strings.rs +++ b/crates/fuzzy_nucleo/src/strings.rs @@ -190,7 +190,7 @@ where return Vec::new(); } - let mut results = segment_results.concat(); + let mut results = segment_results.into_iter().flatten().collect::>(); gpui_util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a)); results }