sum_tree: Reduce Cursor size for contextless summary types (#38776)
This reduces the size of cursor by a usize when the summary does not
require a context making Cursor usages and constructions slightly more
efficient.
This change is a bit annoying though, as Rust has no means of
specializing, so this uses a `ContextlessSummary` trait with a blanket
impl while turning the `Context` into a GAT `Context<'a>`. This means
`Summary` implies are a bit more verbose now while contextless ones are
slimmer. It does come with the downside that the lifetime in the GAT is
always considered invariant, so some lifetime splitting occurred due to
that.
```
push/4096 time: [352.65 µs 360.87 µs 367.80 µs]
thrpt: [10.621 MiB/s 10.825 MiB/s 11.077 MiB/s]
change:
time: [-2.6633% -1.3640% -0.0561%] (p = 0.05 < 0.05)
thrpt: [+0.0561% +1.3828% +2.7361%]
Change within noise threshold.
Found 16 outliers among 100 measurements (16.00%)
7 (7.00%) low severe
3 (3.00%) low mild
2 (2.00%) high mild
4 (4.00%) high severe
push/65536 time: [1.2917 ms 1.2949 ms 1.2979 ms]
thrpt: [48.156 MiB/s 48.267 MiB/s 48.387 MiB/s]
change:
time: [+1.4428% +1.9844% +2.5299%] (p = 0.00 < 0.05)
thrpt: [-2.4675% -1.9458% -1.4223%]
Performance has regressed.
Found 3 outliers among 100 measurements (3.00%)
1 (1.00%) low severe
1 (1.00%) low mild
1 (1.00%) high severe
append/4096 time: [677.87 ns 678.87 ns 679.83 ns]
thrpt: [5.6112 GiB/s 5.6192 GiB/s 5.6274 GiB/s]
change:
time: [-0.8924% -0.5017% -0.1705%] (p = 0.00 < 0.05)
thrpt: [+0.1708% +0.5043% +0.9004%]
Change within noise threshold.
Found 2 outliers among 100 measurements (2.00%)
1 (1.00%) low mild
1 (1.00%) high mild
append/65536 time: [9.3275 µs 9.3406 µs 9.3536 µs]
thrpt: [6.5253 GiB/s 6.5344 GiB/s 6.5435 GiB/s]
change:
time: [+0.5409% +0.7215% +0.9054%] (p = 0.00 < 0.05)
thrpt: [-0.8973% -0.7163% -0.5380%]
Change within noise threshold.
slice/4096 time: [27.673 µs 27.791 µs 27.907 µs]
thrpt: [139.97 MiB/s 140.56 MiB/s 141.16 MiB/s]
change:
time: [-1.1065% -0.6725% -0.2429%] (p = 0.00 < 0.05)
thrpt: [+0.2435% +0.6770% +1.1189%]
Change within noise threshold.
Found 5 outliers among 100 measurements (5.00%)
4 (4.00%) low mild
1 (1.00%) high mild
slice/65536 time: [507.55 µs 517.40 µs 535.60 µs]
thrpt: [116.69 MiB/s 120.80 MiB/s 123.14 MiB/s]
change:
time: [-1.3489% +0.0599% +2.2591%] (p = 0.96 > 0.05)
thrpt: [-2.2092% -0.0598% +1.3674%]
No change in performance detected.
Found 8 outliers among 100 measurements (8.00%)
5 (5.00%) low mild
2 (2.00%) high mild
1 (1.00%) high severe
bytes_in_range/4096 time: [3.3917 µs 3.4108 µs 3.4313 µs]
thrpt: [1.1117 GiB/s 1.1184 GiB/s 1.1247 GiB/s]
change:
time: [-5.3466% -4.7193% -4.1262%] (p = 0.00 < 0.05)
thrpt: [+4.3038% +4.9531% +5.6487%]
Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
1 (1.00%) low mild
5 (5.00%) high mild
bytes_in_range/65536 time: [88.175 µs 88.613 µs 89.111 µs]
thrpt: [701.37 MiB/s 705.31 MiB/s 708.82 MiB/s]
change:
time: [-0.6935% +0.3769% +1.4655%] (p = 0.50 > 0.05)
thrpt: [-1.4443% -0.3755% +0.6984%]
No change in performance detected.
Found 2 outliers among 100 measurements (2.00%)
2 (2.00%) high mild
chars/4096 time: [678.70 ns 680.38 ns 682.08 ns]
thrpt: [5.5927 GiB/s 5.6067 GiB/s 5.6206 GiB/s]
change:
time: [-0.6969% -0.2755% +0.1485%] (p = 0.20 > 0.05)
thrpt: [-0.1483% +0.2763% +0.7018%]
No change in performance detected.
Found 9 outliers among 100 measurements (9.00%)
5 (5.00%) low mild
4 (4.00%) high mild
chars/65536 time: [12.720 µs 12.775 µs 12.830 µs]
thrpt: [4.7573 GiB/s 4.7778 GiB/s 4.7983 GiB/s]
change:
time: [-0.6172% -0.1110% +0.4179%] (p = 0.68 > 0.05)
thrpt: [-0.4162% +0.1112% +0.6211%]
No change in performance detected.
Found 2 outliers among 100 measurements (2.00%)
1 (1.00%) low mild
1 (1.00%) high mild
clip_point/4096 time: [33.240 µs 33.310 µs 33.394 µs]
thrpt: [116.98 MiB/s 117.27 MiB/s 117.52 MiB/s]
change:
time: [-2.8892% -2.6305% -2.3438%] (p = 0.00 < 0.05)
thrpt: [+2.4000% +2.7015% +2.9751%]
Performance has improved.
Found 12 outliers among 100 measurements (12.00%)
1 (1.00%) low mild
4 (4.00%) high mild
7 (7.00%) high severe
clip_point/65536 time: [1.6531 ms 1.6586 ms 1.6640 ms]
thrpt: [37.560 MiB/s 37.683 MiB/s 37.808 MiB/s]
change:
time: [-6.6381% -5.9395% -5.2680%] (p = 0.00 < 0.05)
thrpt: [+5.5610% +6.3146% +7.1100%]
Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
1 (1.00%) low mild
2 (2.00%) high mild
4 (4.00%) high severe
point_to_offset/4096 time: [11.586 µs 11.603 µs 11.621 µs]
thrpt: [336.15 MiB/s 336.67 MiB/s 337.16 MiB/s]
change:
time: [-14.289% -14.111% -13.939%] (p = 0.00 < 0.05)
thrpt: [+16.197% +16.429% +16.672%]
Performance has improved.
Found 12 outliers among 100 measurements (12.00%)
3 (3.00%) low severe
5 (5.00%) low mild
4 (4.00%) high mild
point_to_offset/65536 time: [527.74 µs 532.08 µs 536.51 µs]
thrpt: [116.49 MiB/s 117.46 MiB/s 118.43 MiB/s]
change:
time: [-6.7825% -4.6235% -2.3533%] (p = 0.00 < 0.05)
thrpt: [+2.4100% +4.8477% +7.2760%]
Performance has improved.
Found 8 outliers among 100 measurements (8.00%)
4 (4.00%) high mild
4 (4.00%) high severe
cursor/4096 time: [16.154 µs 16.192 µs 16.232 µs]
thrpt: [240.66 MiB/s 241.24 MiB/s 241.81 MiB/s]
change:
time: [-3.2536% -2.9145% -2.5526%] (p = 0.00 < 0.05)
thrpt: [+2.6194% +3.0019% +3.3630%]
Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
1 (1.00%) low mild
2 (2.00%) high mild
2 (2.00%) high severe
cursor/65536 time: [509.60 µs 511.24 µs 512.93 µs]
thrpt: [121.85 MiB/s 122.25 MiB/s 122.65 MiB/s]
change:
time: [-7.3677% -6.6017% -5.7840%] (p = 0.00 < 0.05)
thrpt: [+6.1391% +7.0683% +7.9537%]
Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
3 (3.00%) high mild
3 (3.00%) high severe
```
Release Notes:
- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -245,7 +245,7 @@ impl ListState {
|
||||
) {
|
||||
let state = &mut *self.0.borrow_mut();
|
||||
|
||||
let mut old_items = state.items.cursor::<Count>(&());
|
||||
let mut old_items = state.items.cursor::<Count>(());
|
||||
let mut new_items = old_items.slice(&Count(old_range.start), Bias::Right);
|
||||
old_items.seek_forward(&Count(old_range.end), Bias::Right);
|
||||
|
||||
@@ -255,9 +255,9 @@ impl ListState {
|
||||
spliced_count += 1;
|
||||
ListItem::Unmeasured { focus_handle }
|
||||
}),
|
||||
&(),
|
||||
(),
|
||||
);
|
||||
new_items.append(old_items.suffix(), &());
|
||||
new_items.append(old_items.suffix(), ());
|
||||
drop(old_items);
|
||||
state.items = new_items;
|
||||
|
||||
@@ -296,7 +296,7 @@ impl ListState {
|
||||
|
||||
let current_offset = self.logical_scroll_top();
|
||||
let state = &mut *self.0.borrow_mut();
|
||||
let mut cursor = state.items.cursor::<ListItemSummary>(&());
|
||||
let mut cursor = state.items.cursor::<ListItemSummary>(());
|
||||
cursor.seek(&Count(current_offset.item_ix), Bias::Right);
|
||||
|
||||
let start_pixel_offset = cursor.start().height + current_offset.offset_in_item;
|
||||
@@ -339,7 +339,7 @@ impl ListState {
|
||||
scroll_top.item_ix = ix;
|
||||
scroll_top.offset_in_item = px(0.);
|
||||
} else {
|
||||
let mut cursor = state.items.cursor::<ListItemSummary>(&());
|
||||
let mut cursor = state.items.cursor::<ListItemSummary>(());
|
||||
cursor.seek(&Count(ix + 1), Bias::Right);
|
||||
let bottom = cursor.start().height + padding.top;
|
||||
let goal_top = px(0.).max(bottom - height + padding.bottom);
|
||||
@@ -368,7 +368,7 @@ impl ListState {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut cursor = state.items.cursor::<Dimensions<Count, Height>>(&());
|
||||
let mut cursor = state.items.cursor::<Dimensions<Count, Height>>(());
|
||||
cursor.seek(&Count(scroll_top.item_ix), Bias::Right);
|
||||
|
||||
let scroll_top = cursor.start().1.0 + scroll_top.offset_in_item;
|
||||
@@ -426,7 +426,7 @@ impl ListState {
|
||||
let state = &self.0.borrow();
|
||||
let logical_scroll_top = state.logical_scroll_top();
|
||||
|
||||
let mut cursor = state.items.cursor::<ListItemSummary>(&());
|
||||
let mut cursor = state.items.cursor::<ListItemSummary>(());
|
||||
let summary: ListItemSummary =
|
||||
cursor.summary(&Count(logical_scroll_top.item_ix), Bias::Right);
|
||||
let content_height = state.items.summary().height;
|
||||
@@ -446,7 +446,7 @@ impl ListState {
|
||||
|
||||
impl StateInner {
|
||||
fn visible_range(&self, height: Pixels, scroll_top: &ListOffset) -> Range<usize> {
|
||||
let mut cursor = self.items.cursor::<ListItemSummary>(&());
|
||||
let mut cursor = self.items.cursor::<ListItemSummary>(());
|
||||
cursor.seek(&Count(scroll_top.item_ix), Bias::Right);
|
||||
let start_y = cursor.start().height + scroll_top.offset_in_item;
|
||||
cursor.seek_forward(&Height(start_y + height), Bias::Left);
|
||||
@@ -478,7 +478,7 @@ impl StateInner {
|
||||
if self.alignment == ListAlignment::Bottom && new_scroll_top == scroll_max {
|
||||
self.logical_scroll_top = None;
|
||||
} else {
|
||||
let mut cursor = self.items.cursor::<ListItemSummary>(&());
|
||||
let mut cursor = self.items.cursor::<ListItemSummary>(());
|
||||
cursor.seek(&Height(new_scroll_top), Bias::Right);
|
||||
let item_ix = cursor.start().count;
|
||||
let offset_in_item = new_scroll_top - cursor.start().height;
|
||||
@@ -519,7 +519,7 @@ impl StateInner {
|
||||
}
|
||||
|
||||
fn scroll_top(&self, logical_scroll_top: &ListOffset) -> Pixels {
|
||||
let mut cursor = self.items.cursor::<ListItemSummary>(&());
|
||||
let mut cursor = self.items.cursor::<ListItemSummary>(());
|
||||
cursor.seek(&Count(logical_scroll_top.item_ix), Bias::Right);
|
||||
cursor.start().height + logical_scroll_top.offset_in_item
|
||||
}
|
||||
@@ -548,7 +548,7 @@ impl StateInner {
|
||||
AvailableSpace::MinContent,
|
||||
);
|
||||
|
||||
let mut cursor = old_items.cursor::<Count>(&());
|
||||
let mut cursor = old_items.cursor::<Count>(());
|
||||
|
||||
// Render items after the scroll top, including those in the trailing overdraw
|
||||
cursor.seek(&Count(scroll_top.item_ix), Bias::Right);
|
||||
@@ -663,11 +663,11 @@ impl StateInner {
|
||||
}
|
||||
|
||||
let measured_range = cursor.start().0..(cursor.start().0 + measured_items.len());
|
||||
let mut cursor = old_items.cursor::<Count>(&());
|
||||
let mut cursor = old_items.cursor::<Count>(());
|
||||
let mut new_items = cursor.slice(&Count(measured_range.start), Bias::Right);
|
||||
new_items.extend(measured_items, &());
|
||||
new_items.extend(measured_items, ());
|
||||
cursor.seek(&Count(measured_range.end), Bias::Right);
|
||||
new_items.append(cursor.suffix(), &());
|
||||
new_items.append(cursor.suffix(), ());
|
||||
self.items = new_items;
|
||||
|
||||
// If none of the visible items are focused, check if an off-screen item is focused
|
||||
@@ -676,7 +676,7 @@ impl StateInner {
|
||||
if !rendered_focused_item {
|
||||
let mut cursor = self
|
||||
.items
|
||||
.filter::<_, Count>(&(), |summary| summary.has_focus_handles);
|
||||
.filter::<_, Count>((), |summary| summary.has_focus_handles);
|
||||
cursor.next();
|
||||
while let Some(item) = cursor.item() {
|
||||
if item.contains_focused(window, cx) {
|
||||
@@ -741,7 +741,7 @@ impl StateInner {
|
||||
offset_in_item: autoscroll_bounds.top() - item_origin.y,
|
||||
});
|
||||
} else if autoscroll_bounds.bottom() > bounds.bottom() {
|
||||
let mut cursor = self.items.cursor::<Count>(&());
|
||||
let mut cursor = self.items.cursor::<Count>(());
|
||||
cursor.seek(&Count(item.index), Bias::Right);
|
||||
let mut height = bounds.size.height - padding.top - padding.bottom;
|
||||
|
||||
@@ -802,7 +802,7 @@ impl StateInner {
|
||||
if self.alignment == ListAlignment::Bottom && new_scroll_top == scroll_max {
|
||||
self.logical_scroll_top = None;
|
||||
} else {
|
||||
let mut cursor = self.items.cursor::<ListItemSummary>(&());
|
||||
let mut cursor = self.items.cursor::<ListItemSummary>(());
|
||||
cursor.seek(&Height(new_scroll_top), Bias::Right);
|
||||
|
||||
let item_ix = cursor.start().count;
|
||||
@@ -946,7 +946,7 @@ impl Element for List {
|
||||
state.items.iter().map(|item| ListItem::Unmeasured {
|
||||
focus_handle: item.focus_handle(),
|
||||
}),
|
||||
&(),
|
||||
(),
|
||||
);
|
||||
|
||||
state.items = new_items;
|
||||
@@ -1027,7 +1027,7 @@ impl Styled for List {
|
||||
impl sum_tree::Item for ListItem {
|
||||
type Summary = ListItemSummary;
|
||||
|
||||
fn summary(&self, _: &()) -> Self::Summary {
|
||||
fn summary(&self, _: ()) -> Self::Summary {
|
||||
match self {
|
||||
ListItem::Unmeasured { focus_handle } => ListItemSummary {
|
||||
count: 1,
|
||||
@@ -1049,14 +1049,12 @@ impl sum_tree::Item for ListItem {
|
||||
}
|
||||
}
|
||||
|
||||
impl sum_tree::Summary for ListItemSummary {
|
||||
type Context = ();
|
||||
|
||||
fn zero(_cx: &()) -> Self {
|
||||
impl sum_tree::ContextLessSummary for ListItemSummary {
|
||||
fn zero() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &Self, _: &()) {
|
||||
fn add_summary(&mut self, summary: &Self) {
|
||||
self.count += summary.count;
|
||||
self.rendered_count += summary.rendered_count;
|
||||
self.unrendered_count += summary.unrendered_count;
|
||||
@@ -1066,33 +1064,33 @@ impl sum_tree::Summary for ListItemSummary {
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ListItemSummary> for Count {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ListItemSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a ListItemSummary, _: ()) {
|
||||
self.0 += summary.count;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ListItemSummary> for Height {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ListItemSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a ListItemSummary, _: ()) {
|
||||
self.0 += summary.height;
|
||||
}
|
||||
}
|
||||
|
||||
impl sum_tree::SeekTarget<'_, ListItemSummary, ListItemSummary> for Count {
|
||||
fn cmp(&self, other: &ListItemSummary, _: &()) -> std::cmp::Ordering {
|
||||
fn cmp(&self, other: &ListItemSummary, _: ()) -> std::cmp::Ordering {
|
||||
self.0.partial_cmp(&other.count).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl sum_tree::SeekTarget<'_, ListItemSummary, ListItemSummary> for Height {
|
||||
fn cmp(&self, other: &ListItemSummary, _: &()) -> std::cmp::Ordering {
|
||||
fn cmp(&self, other: &ListItemSummary, _: ()) -> std::cmp::Ordering {
|
||||
self.0.partial_cmp(&other.height).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user