Implement new recursive change-count matching algorithm for instance reconciliation

- Introduced a comprehensive rewrite of the matching algorithm, replacing the previous multi-pass approach with a recursive change-count scoring function and greedy assignment strategy.
- Updated the `hydrate.lua` and `matching.lua` files to utilize the new algorithm, enhancing the efficiency of instance matching during hydration.
- Documented the new algorithm's structure, including fast-paths for Ref pins and (Name, ClassName) grouping, which significantly improve matching accuracy and performance.
- Ensured that the new implementation maintains compatibility with existing systems while providing a more robust solution for handling ambiguous instances.

These changes enhance the clarity and efficiency of the reconciliation process, paving the way for improved project management and user experience.
This commit is contained in:
Joe 2026-02-17 03:54:06 -06:00
parent 4cb45cd607
commit 1a1d9ce886
14 changed files with 1047 additions and 1108 deletions

View file

@ -2,10 +2,9 @@
Defines the process of "hydration" -- matching up a virtual DOM with
concrete instances and assigning them IDs.
Uses the 3-pass matching algorithm to handle duplicate-named instances:
Pass 1: unique name + ClassName narrowing
Pass 2: Ref property discriminators (using pre-matched UIDs)
Pass 3: structural fingerprinting + pairwise similarity
Uses the change-count matching algorithm to handle duplicate-named
instances: groups by (Name, ClassName), then greedy-assigns pairs
by fewest total reconciler changes (recursive into subtrees).
]]
local Packages = script.Parent.Parent.Parent.Packages
@ -42,12 +41,7 @@ local function hydrate(instanceMap, virtualInstances, rootId, rootInstance)
end
-- Use the 3-pass matching algorithm to pair virtual ↔ studio children
local result = Matching.matchChildren(
validVirtualIds,
existingChildren,
virtualInstances,
instanceMap
)
local result = Matching.matchChildren(validVirtualIds, existingChildren, virtualInstances, instanceMap)
-- Recursively hydrate matched pairs
for _, pair in result.matched do