Improve performance of create_highlight_endpoints (#58119)

This change gets rid of the tree traversal overhead by batching the
anchor resolution

> Create highlight endpoints/text_highlights/100
>                         time:   [298.43 µs 298.55 µs 298.69 µs]

> Create highlight endpoints/text_highlights/100
>                         time:   [40.347 µs 40.386 µs 40.427 µs]
> change: [-86.492% -86.481% -86.471%] (p = 0.00 < 0.05)
>                         Performance has improved.

This is especially important given that `CustomHighlightsChunks::seek`
tends to get called a lot, which re-creates highlight endpoints a lot.

Release Notes:

- N/A or Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth authored and GitHub committed 2026-05-31 15:19:20 +00:00
1 parent fd93a53c17
commit 876ec5a8a0
3 files changed
+232 -72

No files matched your search

+19 -8
View File
@@ -5003,6 +5003,20 @@ impl MultiBufferSnapshot {
}
pub fn summaries_for_anchors<'a, MBD, I>(&'a self, anchors: I) -> Vec<MBD>
where
MBD: MultiBufferDimension
+ Ord
+ Sub<Output = MBD::TextDimension>
+ AddAssign<MBD::TextDimension>,
MBD::TextDimension: Sub<Output = MBD::TextDimension> + Ord,
I: 'a + IntoIterator<Item = &'a Anchor>,
{
let mut summaries = Vec::new();
self.summaries_for_anchors_cb(anchors, |summary| summaries.push(summary));
summaries
}
pub fn summaries_for_anchors_cb<'a, MBD, I>(&'a self, anchors: I, mut cb: impl FnMut(MBD))
where
MBD: MultiBufferDimension
+ Ord
@@ -5018,18 +5032,17 @@ impl MultiBufferSnapshot {
.cursor::<Dimensions<ExcerptDimension<MBD>, OutputDimension<MBD>>>(());
diff_transforms_cursor.next();
let mut summaries = Vec::new();
while let Some(anchor) = anchors.peek() {
let target = anchor.seek_target(self);
let excerpt_anchor = match anchor {
Anchor::Min => {
summaries.push(MBD::default());
cb(MBD::default());
anchors.next();
continue;
}
Anchor::Excerpt(excerpt_anchor) => excerpt_anchor,
Anchor::Max => {
summaries.push(MBD::from_summary(&self.text_summary()));
cb(MBD::from_summary(&self.text_summary()));
anchors.next();
continue;
}
@@ -5047,7 +5060,7 @@ impl MultiBufferSnapshot {
excerpt_start_position,
&mut diff_transforms_cursor,
);
summaries.push(position);
cb(position);
anchors.next();
continue;
}
@@ -5083,7 +5096,7 @@ impl MultiBufferSnapshot {
diff_transforms_cursor.seek_forward(&position, Bias::Left);
}
summaries.push(self.summary_for_anchor_with_excerpt_position(
cb(self.summary_for_anchor_with_excerpt_position(
excerpt_anchor,
position,
&mut diff_transforms_cursor,
@@ -5097,12 +5110,10 @@ impl MultiBufferSnapshot {
excerpt_start_position,
&mut diff_transforms_cursor,
);
summaries.push(position);
cb(position);
anchors.next();
}
}
summaries
}
pub fn dimensions_from_points<'a, MBD>(