Enhance matching module with reference identity and caching improvements

- Introduced a new `RefIdentity` type to store reference details (name and className) in the matching process.
- Updated `VCache` and `SCache` structures to include references, improving the handling of reference comparisons during matching.
- Modified `cacheVirtual` and `cacheStudio` functions to support reference caching, enhancing performance and accuracy in matching.
- Improved `countOwnDiffs` function to account for reference mismatches, ensuring more precise cost calculations.
- Added comprehensive tests to validate the new reference handling and caching mechanisms.

These changes significantly enhance the efficiency and accuracy of the matching process in the application.
This commit is contained in:
Joe 2026-02-18 06:16:33 -06:00
parent bf4aef6e94
commit b687c8862d
12 changed files with 1401 additions and 61 deletions

View file

@ -758,4 +758,150 @@ mod tests {
assert_eq!(a, b);
}
}
#[test]
fn total_cost_zero_identical() {
let (new_dom, new_root, _, _) = build_test_dom();
let (old_dom, old_root, _, _) = build_test_dom();
let new_children: Vec<Ref> = new_dom.get_by_ref(new_root).unwrap().children().to_vec();
let old_children: Vec<Ref> = old_dom.get_by_ref(old_root).unwrap().children().to_vec();
let result = match_children(
&new_children,
&old_children,
&new_dom,
&old_dom,
None,
None,
&MatchingSession::new(),
);
assert_eq!(result.matched.len(), 2);
assert_eq!(
result.total_cost, 0,
"Identical instances should have zero cost"
);
}
#[test]
fn total_cost_nonzero_different() {
use rbx_dom_weak::types::Variant;
let mut new_dom = WeakDom::new(InstanceBuilder::new("DataModel"));
let new_root = new_dom.root_ref();
new_dom.insert(
new_root,
InstanceBuilder::new("Part")
.with_name("P")
.with_property("Transparency", Variant::Float32(0.5)),
);
let mut old_dom = WeakDom::new(InstanceBuilder::new("DataModel"));
let old_root = old_dom.root_ref();
old_dom.insert(
old_root,
InstanceBuilder::new("Part")
.with_name("P")
.with_property("Transparency", Variant::Float32(0.0)),
);
let new_children: Vec<Ref> = new_dom.get_by_ref(new_root).unwrap().children().to_vec();
let old_children: Vec<Ref> = old_dom.get_by_ref(old_root).unwrap().children().to_vec();
let result = match_children(
&new_children,
&old_children,
&new_dom,
&old_dom,
None,
None,
&MatchingSession::new(),
);
assert_eq!(result.matched.len(), 1);
assert!(
result.total_cost > 0,
"Different properties should produce nonzero cost, got {}",
result.total_cost
);
}
#[test]
fn total_cost_includes_unmatched() {
let mut new_dom = WeakDom::new(InstanceBuilder::new("DataModel"));
let new_root = new_dom.root_ref();
new_dom.insert(
new_root,
InstanceBuilder::new("Folder").with_name("A"),
);
new_dom.insert(
new_root,
InstanceBuilder::new("Folder").with_name("B"),
);
new_dom.insert(
new_root,
InstanceBuilder::new("Folder").with_name("C"),
);
let mut old_dom = WeakDom::new(InstanceBuilder::new("DataModel"));
let old_root = old_dom.root_ref();
old_dom.insert(
old_root,
InstanceBuilder::new("Folder").with_name("A"),
);
old_dom.insert(
old_root,
InstanceBuilder::new("Folder").with_name("B"),
);
let new_children: Vec<Ref> = new_dom.get_by_ref(new_root).unwrap().children().to_vec();
let old_children: Vec<Ref> = old_dom.get_by_ref(old_root).unwrap().children().to_vec();
let result = match_children(
&new_children,
&old_children,
&new_dom,
&old_dom,
None,
None,
&MatchingSession::new(),
);
assert_eq!(result.matched.len(), 2);
assert_eq!(result.unmatched_new.len(), 1);
assert!(
result.total_cost >= UNMATCHED_PENALTY,
"Should include penalty for unmatched, got {}",
result.total_cost
);
}
#[test]
fn session_cache_consistent_syncback() {
let (new_dom, new_root, _, _) = build_test_dom();
let (old_dom, old_root, _, _) = build_test_dom();
let new_children: Vec<Ref> = new_dom.get_by_ref(new_root).unwrap().children().to_vec();
let old_children: Vec<Ref> = old_dom.get_by_ref(old_root).unwrap().children().to_vec();
let session = MatchingSession::new();
let r1 = match_children(
&new_children,
&old_children,
&new_dom,
&old_dom,
None,
None,
&session,
);
let r2 = match_children(
&new_children,
&old_children,
&new_dom,
&old_dom,
None,
None,
&session,
);
assert_eq!(r1.matched.len(), r2.matched.len());
assert_eq!(r1.total_cost, r2.total_cost);
}
}