forked from 1b-agent/opencadstudio-upstream
perf(plotstyle): extract and speed up layer-usage table rebuild
view_window() rebuilt the 256-bucket ACI layer-usage table inline on every modal view: unconditional 256-Vec allocation plus sort_by_key (lowercase key recomputed per comparison). Extract pure build_layer_usage(), build it only when the CTB path needs it (STB path now allocates nothing), and sort with sort_by_cached_key while skipping trivial buckets. Tests: - build_layer_usage_buckets_index_colors: ACI bucketing + case-insensitive order - build_layer_usage_ignores_non_index_colors: truecolor layers excluded Bench (cargo bench ui_plotstyle_layer_usage, 200 layers): ~13us median, PASS. A/B vs pre-change inline code: ~15.7us -> ~12-13us (~22% faster).
This commit is contained in:
1 parent
768ce2ca82
commit
70d7e9a31f
3 files changed
+141
-18
No files matched your search
@@ -13,6 +13,7 @@
|
||||
//! 10. UI Ribbon View Widget Tree Construction
|
||||
//! 11. UI Viewport Grid Geometry Projection & Overlay Cache Key Evaluation
|
||||
//! 12. UI Themed SVG Icon Lookup Caching vs Uncached Parse
|
||||
//! 12b. Plot Style Layer-Usage Table Rebuild (256-bucket ACI table)
|
||||
//! 13. Wide & Tapered Arc + Donut Tessellation (7.5k offset polyline curves)
|
||||
//! 14. Model Space Extents & Bounding Box Calculation (ZOOM EXTENTS)
|
||||
//! 15. Batch Entity Transformation & Incremental Dirty-Tracking
|
||||
@@ -64,6 +65,7 @@ use OpenCADStudio::ui::overlay::{
|
||||
};
|
||||
use OpenCADStudio::ui::properties::LinetypeItem;
|
||||
use OpenCADStudio::ui::ribbon::{LayerInfo, Ribbon};
|
||||
use OpenCADStudio::ui::style::plotstyle::build_layer_usage;
|
||||
|
||||
// ── Metric Structures ───────────────────────────────────────────────────────
|
||||
|
||||
@@ -1359,6 +1361,53 @@ fn bench_ui_icon_caching(runner: &mut BenchmarkRunner) {
|
||||
}
|
||||
}
|
||||
|
||||
// ── 12b. Plot Style Layer-Usage Table Rebuild ───────────────────────────────
|
||||
// Covers Mission #19 `build_layer_usage`: layer names bucketed by ACI into a
|
||||
// 256-bucket table, rebuilt per Plot Style modal view.
|
||||
|
||||
fn bench_ui_plotstyle_layer_usage(runner: &mut BenchmarkRunner) {
|
||||
if !runner.should_run("ui_plotstyle_layer_usage") {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut doc = CadDocument::new();
|
||||
for i in 0..200 {
|
||||
let mut layer = acadrust::tables::Layer::new(&format!("LAYER_{i:03}"));
|
||||
layer.handle = doc.allocate_handle();
|
||||
layer.color = acadrust::types::Color::Index((i % 8 + 1) as u8);
|
||||
let _ = doc.layers.add(layer);
|
||||
}
|
||||
|
||||
// Warm-up for allocator settling
|
||||
for _ in 0..10 {
|
||||
let _ = black_box(build_layer_usage(&doc));
|
||||
}
|
||||
|
||||
let n = if runner.quick_mode { 20 } else { 100 };
|
||||
let runs = 5;
|
||||
let mut samples = Vec::with_capacity(runs);
|
||||
|
||||
for _ in 0..runs {
|
||||
let t0 = Instant::now();
|
||||
for _ in 0..n {
|
||||
let usage = build_layer_usage(black_box(&doc));
|
||||
black_box(usage);
|
||||
}
|
||||
let per_us = (t0.elapsed().as_micros() as f64) / (n as f64);
|
||||
samples.push(per_us);
|
||||
}
|
||||
|
||||
let median_us = samples[samples.len() / 2];
|
||||
runner.record(
|
||||
"ui_plotstyle_layer_usage",
|
||||
"Plot Style 256-bucket ACI layer-usage table rebuild (200 layers, 8 buckets x25)",
|
||||
"µs",
|
||||
samples,
|
||||
Some((1_000_000.0 / median_us, "rebuilds/s")),
|
||||
Some(50.0), // Target threshold < 50 µs
|
||||
);
|
||||
}
|
||||
|
||||
// ── 13. Wide & Tapered Arc + Donut Tessellation ─────────────────────────────
|
||||
|
||||
fn bench_wide_and_tapered_arc_tessellation(runner: &mut BenchmarkRunner) {
|
||||
@@ -1761,6 +1810,7 @@ fn main() {
|
||||
bench_ui_ribbon_view_construction(&mut runner);
|
||||
bench_ui_grid_geometry(&mut runner);
|
||||
bench_ui_icon_caching(&mut runner);
|
||||
bench_ui_plotstyle_layer_usage(&mut runner);
|
||||
bench_wide_and_tapered_arc_tessellation(&mut runner);
|
||||
bench_zoom_extents_calculation(&mut runner);
|
||||
bench_batch_entity_mutation(&mut runner);
|
||||
|
||||
Reference in new issue
Block a user