From cdcce048fec5109138589f06535359d206183445 Mon Sep 17 00:00:00 2001 From: audichuang <72485427+audichuang@users.noreply.github.com> Date: Wed, 25 Nov 2026 14:25:10 +0800 Subject: [PATCH] perf(search): pass each long-line window only the ranges that start in it (#5754) On a line cut into windows, every window was handed all the matches left on the line and in_window reserved room for each, so the reservation added up to windows x matches: searching a 5 MB minified line asked the allocator for about 5 GiB. Each window now gets only the ranges that start in it (partition_point on the sorted ranges); in_window and the matches it returns are unchanged. Co-authored-by: audichuang <72485427+audichuang@users.noreply.github.com> --- crates/ide-search/src/line.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/ide-search/src/line.rs b/crates/ide-search/src/line.rs index 7e1e93da65..c89db85f77 100644 --- a/crates/ide-search/src/line.rs +++ b/crates/ide-search/src/line.rs @@ -46,7 +46,10 @@ fn from_str(line_no: u32, s: &str, ranges: &[(usize, usize)], out: &mut Vec = s.match_indices("function").map(|(a, m)| (a, a + m.len())).collect(); + let mut out = Vec::new(); + line_matches(0, s.as_bytes(), &ranges, &mut out); + let reserved: usize = out.iter().map(|m| m.ranges.capacity()).sum(); + assert!(reserved <= 4 * out.len(), "{reserved} ranges reserved for {} windows", out.len()); + } + /// `main`'s windowing, which counts each window's offset from the line start. fn reference(line_no: u32, line: &[u8], ranges: &[(usize, usize)]) -> Vec { fn from_str(line_no: u32, s: &str, ranges: &[(usize, usize)], out: &mut Vec) {