ui-bench: menu-80-rows, inspector-1000-fields and --only; trial of component runs per menu row

This commit is contained in:
aiongg
2026-11-20 18:17:34 +00:00
parent 6769a5ca21
commit e80eacc2ab
5 changed files with 69 additions and 11 deletions
+22 -9
View File
@@ -66,16 +66,17 @@ impl Library for Foundation {
fn build(&self, name: &str) -> SceneBuild {
let (scene, equivalent): (Box<dyn Scene>, &'static str) = match name {
"inspector-500-fields" => (
Box::new(InspectorScene::new()),
"inspector-500-fields" | "inspector-1000-fields" => (
Box::new(InspectorScene::new(if name == "inspector-500-fields" { 500 } else { 1000 })),
// F8-MERGE: family (Field row): the field's own side label stands in for the `Field` row.
"500 rows alternating NumberField and TextField, each with its side label (no Field row component yet)",
"500 (or 1000) rows alternating NumberField and TextField, each with its side label (no Field row component yet)",
),
"virtual-list-10000" => (Box::new(ListScene::new(Selected::None)), "List over 10,000 ListRow rows, one selected row"),
"sheet-50x200" => (Box::new(SheetScene), "BenchList of 200 rows, each with 50 cell parts that paint their text"),
// F8-MERGE: canvas: the canvas component and its declared controls.
"canvas-50-controls" => (Box::new(CanvasScene), "a leaf with 50 control parts painted as knobs"),
"menu-40-rows" => (Box::new(MenuScene), "a Menu open from the first frame over 40 MenuItem rows"),
"menu-40-rows" => (Box::new(MenuScene { rows: 40 }), "a Menu open from the first frame over 40 MenuItem rows"),
"menu-80-rows" => (Box::new(MenuScene { rows: 80 }), "a Menu open from the first frame over 80 MenuItem rows"),
"table-1000x5" => (Box::new(TableScene), "a Table of 1,000 rows and 5 columns, text in every cell"),
"tile-grid-500" => (Box::new(TileGridScene), "a TileGrid of 500 Tiles"),
"text-field-100kb" => (Box::new(TextScene::new()), "TextField::lines(30) bound with Bind::bound over a 100 KB String"),
@@ -114,8 +115,8 @@ struct InspectorScene {
}
impl InspectorScene {
fn new() -> Self {
Self { values: (0..500).map(|i| Some(f64::from(i))).collect(), texts: (0..500).map(|i| format!("Value {i}")).collect() }
fn new(count: i32) -> Self {
Self { values: (0..count).map(|i| Some(f64::from(i))).collect(), texts: (0..count).map(|i| format!("Value {i}")).collect() }
}
}
@@ -195,7 +196,10 @@ impl Scene for CanvasScene {
}
}
struct MenuScene;
/// A menu open over `rows` items.
struct MenuScene {
rows: usize,
}
impl Scene for MenuScene {
fn size(&self) -> Vec2 {
@@ -205,7 +209,7 @@ impl Scene for MenuScene {
fn show(&mut self, ui: &mut Ui, _frame: u64) {
let mut open = true;
let _ = Menu::new("Items").open(Bind::bound(&mut open)).id_salt("menu").show(ui, |ui, _| {
for key in 0..40 {
for key in 0..self.rows {
let _ = MenuItem::new(format!("Item {key}")).id_salt(key).show(ui);
}
});
@@ -533,8 +537,17 @@ impl Scene for ReadoutScene {
}
fn main() -> std::process::ExitCode {
let report = run_all(&Foundation { root: RootEnv::default() });
// `--only <scenario>` runs one scenario and prints its row: for profiling, it writes no baseline and runs no gate.
let mut args = std::env::args().skip(1);
let only = match (args.next().as_deref(), args.next()) {
(Some("--only"), Some(name)) => Some(name),
_ => None,
};
let report = run_all(&Foundation { root: RootEnv::default() }, only.as_deref());
print_table(&report);
if only.is_some() {
return std::process::ExitCode::SUCCESS;
}
let baseline = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("baseline");
let outcome = write_json(&report, &baseline.join("foundation.json")).and_then(|()| read_json(&baseline.join("legacy.json")));
let legacy = match outcome {
+3 -2
View File
@@ -114,10 +114,11 @@ fn measure(library: &dyn Library, mut scene: Box<dyn Scene>) -> Measurement {
)
}
/// Measures every scenario of [`SCENARIOS`] on `library`.
pub fn run_all(library: &dyn Library) -> Report {
/// Measures every scenario of [`SCENARIOS`] on `library`, or only the one called `only`.
pub fn run_all(library: &dyn Library, only: Option<&str>) -> Report {
let scenarios = SCENARIOS
.iter()
.filter(|scenario| only.is_none_or(|name| scenario.name == name))
.map(|scenario| {
eprintln!("{}: {}", library.name(), scenario.name);
let (equivalent, missing, measurement) = match library.build(scenario.name) {
+2
View File
@@ -15,10 +15,12 @@ pub struct Scenario {
/// Every scenario, in report order.
pub const SCENARIOS: &[Scenario] = &[
Scenario { name: "inspector-500-fields", description: "an inspector of 500 Field rows", no_discard: false },
Scenario { name: "inspector-1000-fields", description: "an inspector of 1,000 Field rows", no_discard: false },
Scenario { name: "virtual-list-10000", description: "a 10,000-item virtual list", no_discard: false },
Scenario { name: "sheet-50x200", description: "a sheet of 50 x 200 visible cells as row parts", no_discard: false },
Scenario { name: "canvas-50-controls", description: "a canvas with 50 canvas controls", no_discard: false },
Scenario { name: "menu-40-rows", description: "an open menu with 40 rows", no_discard: false },
Scenario { name: "menu-80-rows", description: "an open menu with 80 rows", no_discard: false },
Scenario { name: "table-1000x5", description: "a table of 1,000 rows and 5 columns", no_discard: false },
Scenario { name: "tile-grid-500", description: "a tile grid of 500 tiles", no_discard: false },
Scenario { name: "text-field-100kb", description: "a 100 KB multi-line text field, bound", no_discard: false },
+2
View File
@@ -16,6 +16,8 @@ mod pick_focus;
mod rows;
mod runs_per_row;
mod search;
mod submenus;
@@ -0,0 +1,40 @@
//! An open menu runs a constant number of components per row: 80 rows run 40 rows' worth more than 40 rows, in the room the
//! `menu-80-rows` scenario of ui-bench gives its menu.
use craft_ui::contract::{Bind, Props as _, Show as _, ShowContainer as _};
use craft_ui::menu::{Menu, MenuItem};
use craft_ui::testing::{Fixture, last_pass_runs, trial};
use egui::vec2;
/// The room of ui-bench's `MenuScene`.
const ROOM: egui::Vec2 = vec2(800.0, 1400.0);
/// The components run in the last pass, and how many of the `rows` have a node.
fn runs_and_rows_shown(rows: usize) -> (u32, usize) {
let mut fixture = Fixture::new(move |ui| {
let mut open = true;
let _ = Menu::new("Items").open(Bind::bound(&mut open)).id_salt("menu").show(ui, |ui, _| {
for key in 0..rows {
let _ = MenuItem::new(format!("Item {key}")).id_salt(key).show(ui);
}
});
});
fixture.room(ROOM);
fixture.settle().idle(2);
let runs = last_pass_runs(fixture.ctx()).iter().map(|(_, runs)| runs).sum();
let shown = (0..rows).filter(|key| fixture.by_label(&format!("Item {key}")).is_some()).count();
(runs, shown)
}
#[trial]
fn component_runs_grow_by_a_constant_per_menu_row() {
let (few, few_shown) = runs_and_rows_shown(40);
let (many, many_shown) = runs_and_rows_shown(80);
eprintln!("menu runs: 40 rows {few} runs ({few_shown} shown), 80 rows {many} runs ({many_shown} shown)");
assert_eq!((few_shown, many_shown), (40, 80), "every row has a node in the bench's room, so runs per row means every row");
let grown = many.checked_sub(few).expect("more rows run no fewer components");
assert_eq!(grown % 40, 0, "runs grow by a constant per row: {few} runs at 40 rows, {many} at 80");
let k = grown / 40;
assert!(k >= 1, "each row runs at least one component");
eprintln!("runs per menu row: {k}");
}