gpui_platform: Add ID churn benchmarks

A new ID churn workload gives every element a new ID each frame, the worst
case for anything keyed by element ID across frames, such as layout nodes
kept between frames. Path-free trees also gain leaf bounds, root layout and
ID churn groups, where layout is most of what is measured.

Release Notes:

- N/A
This commit is contained in:
Anthony Eid committed 2026-11-09 03:58:33 -05:00
1 parent ddb90e5e89
commit 12a16ba09c
3 files changed
+66 -9

No files matched your search

+17 -2
View File
@@ -612,6 +612,7 @@ impl RandomizedElementTree {
cached_views: config.cached_views,
hover_styles: config.hover_styles,
paths: config.paths,
id_generation: 0,
},
paths_by_element_id: HashMap::default(),
};
@@ -735,6 +736,14 @@ impl RandomizedElementTree {
true
}
/// Gives every element a new ID, as when a list's items are keyed by data that
/// changes every frame, and re-renders the whole tree. Nothing else changes, so each
/// element's state is lost but its layout and paint are as before.
pub fn churn_element_ids(&mut self, cx: &mut Context<Self>) {
self.snapshot.borrow_mut().render_options.id_generation += 1;
cx.notify();
}
/// Generates and inserts an element below a seeded random parent.
///
/// This does not synchronize or notify persistent child entities. Entity-aware callers should
@@ -1173,11 +1182,16 @@ impl Render for RandomizedElementTree {
type RandomizedElementEntities = HashMap<u64, Entity<RandomizedElementEntity>>;
/// Element IDs carry the tree's ID generation above this bit, so churning IDs never
/// changes the element number the low bits identify.
const ID_GENERATION_SHIFT: u32 = 32;
#[derive(Clone, Copy, Debug, PartialEq)]
struct RenderOptions {
cached_views: bool,
hover_styles: bool,
paths: bool,
id_generation: u64,
}
struct RandomizedElementEntity {
@@ -1411,7 +1425,7 @@ fn render_node_body(
div()
.id(ElementId::NamedInteger(
"randomized-element".into(),
node.id,
node.id | options.id_generation << ID_GENERATION_SHIFT,
))
.flex()
.flex_shrink_0()
@@ -1766,7 +1780,8 @@ mod tests {
let ElementId::NamedInteger(name, element_id) = global_id.last()? else {
return None;
};
(name.as_ref() == "randomized-element").then_some(*element_id)
(name.as_ref() == "randomized-element")
.then_some(element_id & ((1 << ID_GENERATION_SHIFT) - 1))
})
.collect(),
}
@@ -395,6 +395,16 @@ fn full_refresh(family: &TreeFamily, mut rng: StdRng, cx: &mut BenchAppContext)
measure_in_window("full refresh", input, cx, |_, window, _| window.refresh());
}
/// Every element gets a new ID each frame and the whole tree renders again, as when a
/// list's items are keyed by data that changes every frame: nothing retained between
/// frames under an element's ID can be found again, so this is the price, on top of a full
/// refresh, of every keyed cache missing.
#[gpui::bench(inputs = families(), input_name = "tree", iterations = 2, group = "RandomizedTree/id churn", fps = 120)]
fn id_churn(family: &TreeFamily, mut rng: StdRng, cx: &mut BenchAppContext) {
let input = &family.sample(&mut rng);
measure("id churn", input, cx, |tree, cx| tree.churn_element_ids(cx));
}
/// The same tree as `family` draws, with elements painting no vector paths. Tessellating
/// paths dominates the frames of trees that paint them, hiding everything else; without
/// them the rest of the frame, layout especially, is most of what is measured.
@@ -420,6 +430,33 @@ fn pathless_element_style(family: &TreeFamily, mut rng: StdRng, cx: &mut BenchAp
measure_element_style("pathless element style", input, cx);
}
/// [`leaf_bounds`] on trees that paint no paths.
#[gpui::bench(inputs = families(), input_name = "tree", iterations = 2, group = "PathlessTree/leaf bounds", fps = 120)]
fn pathless_leaf_bounds(family: &TreeFamily, mut rng: StdRng, cx: &mut BenchAppContext) {
let input = &sample_without_paths(family, &mut rng);
measure("pathless leaf bounds", input, cx, |tree, cx| {
tree.apply_mutation(RandomizedElementTreeMutationKind::ChildBounds, cx);
});
}
/// [`root_layout`] on trees that paint no paths.
#[gpui::bench(inputs = families(), input_name = "tree", iterations = 2, group = "PathlessTree/root layout", fps = 120)]
fn pathless_root_layout(family: &TreeFamily, mut rng: StdRng, cx: &mut BenchAppContext) {
let input = &sample_without_paths(family, &mut rng);
measure("pathless root layout", input, cx, |tree, cx| {
tree.apply_mutation(RandomizedElementTreeMutationKind::RootBounds, cx);
});
}
/// [`id_churn`] on trees that paint no paths.
#[gpui::bench(inputs = families(), input_name = "tree", iterations = 2, group = "PathlessTree/id churn", fps = 120)]
fn pathless_id_churn(family: &TreeFamily, mut rng: StdRng, cx: &mut BenchAppContext) {
let input = &sample_without_paths(family, &mut rng);
measure("pathless id churn", input, cx, |tree, cx| {
tree.churn_element_ids(cx)
});
}
/// A frame in which the root is notified but nothing in the tree changed. On a renderer
/// that rebuilds every frame this is the whole tree's cost; on one that retains output
/// it is the floor for a frame that has to do nothing.
@@ -1590,8 +1627,12 @@ gpui::bench_group!(
reorder,
hover,
mixed,
id_churn,
pathless_full_refresh,
pathless_element_style,
pathless_leaf_bounds,
pathless_root_layout,
pathless_id_churn,
changing_share,
text_panel_updates,
installed_font_panel_updates,
+8 -7
View File
@@ -11,13 +11,13 @@ samples and summary.json persist under target/gpui-bench-compare. Nothing
switches the invoking checkout or publishes a branch.
The default core suite keeps the mixed workload (plain and with cached views),
five full-refresh tree shapes with and without paths, element style, cached
element style, pointer hover, warm installed-font text, text first frame, three
scrolling workloads, random and patterned primitive painting, and two inspector
workloads. --full selects every variant; --slow restores the benchmarks' own
Criterion settings (including inspector's five-second measurement).
--repetitions controls independent runs, not random seeds. Use --seed to
compare another fixed tree.
five full-refresh tree shapes with and without paths, ID churn, element style,
cached element style, pointer hover, warm installed-font text, text first frame,
three scrolling workloads, random and patterned primitive painting, and two
inspector workloads. --full selects every variant; --slow restores the
benchmarks' own Criterion settings (including inspector's five-second
measurement). --repetitions controls independent runs, not random seeds. Use
--seed to compare another fixed tree.
Foreground retired instructions are primary. Linux needs perf access
(CAP_PERFMON or perf_event_paranoid <= 2); macOS needs Apple Silicon. Frames run
@@ -59,6 +59,7 @@ CORE = {
r"^((Randomized|Cached)Tree/mixed/tree/mixed/|"
r"RandomizedTree/full refresh/tree/|"
r"PathlessTree/full refresh/tree/|"
r"(Randomized|Pathless)Tree/id churn/tree/mixed/|"
r"RandomizedTree/element style/tree/mixed/|"
r"CachedTree/element style/tree/mixed/|"
r"RandomizedTree/hover/tree/mixed/|"