perf(#3892): index the hidden joints and folders of the view (#9823)

The browser asks about every joint of the design on every frame, and
the answer walked the list of hidden joints: a nested STEP assembly
hides thousands of them, so a frame cost grew with the size of the
design.

Session keeps the hidden joints and folders as sets and answers from
them. The sets are built when the view changes and kept until it
changes again: the revision says the design changed, and the lists
say the view changed under it (the view is replaced outside the
engine too, without a revision of its own).

The behaviour is unchanged: the hidden joint stays hidden, the shown
one stays shown, and undo and redo keep the hiding right.
This commit is contained in:
Homero Thompson
2026-10-31 03:01:33 +00:00
committed by GitHub
parent d7ae568790
commit 810a9558bd
3 changed files with 252 additions and 1 deletions
+81
View File
@@ -1287,6 +1287,87 @@ fn hidden_joints_still_drive_and_are_saved_with_the_design() {
let _ = std::fs::remove_dir_all(&dir);
}
/// #3892: a large nested STEP assembly hides thousands of joints, and the browser asks about
/// every joint of the design on every frame: the answer must not walk the hidden-joint list,
/// so the work must not grow with the number of hidden joints. The hidden joint stays hidden,
/// the shown one stays shown, and undo and redo keep the hiding right.
#[test]
fn hidden_joint_lookups_do_not_walk_the_hidden_joint_list() {
use crate::occurrences::visibility_work;
let mut s = hinged();
let (hinge, glue) = (joint(&s, "Hinge"), joint(&s, "Glue"));
// The hidden joints of an imported assembly: thousands of ids (#3892).
let hide_many = |s: &mut Session, n: u64| {
s.visibility.hidden_joints.clear();
for id in 0..n {
s.visibility.hidden_joints.push(id);
}
};
// The entries one lookup walked, for a joint that is not hidden.
let walked_by = |s: &Session, id: u64| {
visibility_work::take();
let visible = s.joint_visible(id);
let walked = visibility_work::take();
assert!(visible, "joint {id} is not hidden here");
walked
};
hide_many(&mut s, 10);
let few = walked_by(&s, 9_000_001);
hide_many(&mut s, 10_000);
let many = walked_by(&s, 9_000_001);
assert!(
many <= few + 4,
"a joint lookup walked {many} entries of a 10,000-entry hidden-joint list and {few} of a \
10-entry one: the work must not grow with the number of hidden joints"
);
// The behaviour is unchanged: the hidden joint is hidden, the shown one is shown, and undo
// and redo keep the hiding right.
s.visibility.hidden_joints.clear();
run(&mut s, "browser.visibility", json!({"joints": ["Hinge"], "visible": false}));
assert!(!s.joint_visible(hinge) && s.joint_visible(glue));
run(&mut s, "edit.undo", json!({}));
assert!(s.joint_visible(hinge), "undo shows the hinge again");
run(&mut s, "edit.redo", json!({}));
assert!(!s.joint_visible(hinge), "redo hides it again");
}
/// The cost of a frame's worth of joint questions, with few and with many hidden joints: the
/// manual measurement behind #3892. Run it with `--ignored --nocapture`.
#[test]
#[ignore = "manual scaling measurement"]
fn joint_visibility_lookup_cost_by_hidden_joint_count() {
use crate::occurrences::visibility_work;
let joints = 1_000u64;
for hidden in [0u64, 10, 100, 1_000, 10_000] {
let mut s = Session::default();
for id in 0..hidden {
s.visibility.hidden_joints.push(id);
}
let mut times = Vec::new();
for _ in 0..11 {
let start = std::time::Instant::now();
for id in 0..joints {
let _ = s.joint_visible(id + hidden + 1);
}
times.push(start.elapsed().as_secs_f64() * 1e3);
}
times.sort_by(f64::total_cmp);
// The index is built once per change of the view, apart from the answers themselves.
println!(
"hidden_joints={hidden:>6} questions={joints} median_ms={:.3} min_ms={:.3} max_ms={:.3} built_entries={}",
times[times.len() / 2],
times[0],
times[times.len() - 1],
visibility_work::built_take()
);
}
}
/// #1160: a design saved before joints could be hidden (format 19, no `hidden_joints`) opens
/// with every joint shown; and a new joint that takes a deleted hidden joint's id starts shown.
#[test]