Add LIS-based differentiator for minimal child reordering mutations (#56094)#56094
Open
javache wants to merge 1 commit intofacebook:mainfrom
Open
Add LIS-based differentiator for minimal child reordering mutations (#56094)#56094javache wants to merge 1 commit intofacebook:mainfrom
javache wants to merge 1 commit intofacebook:mainfrom
Conversation
javache
added a commit
to javache/react-native
that referenced
this pull request
Mar 14, 2026
…acebook#56094) Summary: The current Differentiator Stage 4 uses a greedy two-pointer algorithm to reconcile reordered children. When children are shuffled, it produces excessive REMOVE+INSERT pairs because it doesn't find the minimal edit. This adds an alternative code path that uses Longest Increasing Subsequence (LIS) to identify which children can stay in place vs which need to be moved. Items in the LIS maintain their relative order — only items outside the LIS need REMOVE+INSERT. Example: moving last element to front [A,B,C,D,E] → [E,A,B,C,D]: - Greedy: 4 REMOVEs + 5 INSERTs = 9 mutations - LIS: LIS=[A,B,C,D], only E moves = 1 REMOVE + 1 INSERT = 2 mutations The LIS algorithm is O(n log n) time, O(n) space. Since average child count is <10, the position mapping uses linear scan instead of hash tables. Guarded by `useLISAlgorithmInDifferentiator` feature flag (default off). Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D96334873
7e71924 to
c0e2626
Compare
…acebook#56094) Summary: Pull Request resolved: facebook#56094 The current Differentiator Stage 4 uses a greedy two-pointer algorithm to reconcile reordered children. When children are shuffled, it produces excessive REMOVE+INSERT pairs because it doesn't find the minimal edit. This adds an alternative code path that uses Longest Increasing Subsequence (LIS) to identify which children can stay in place vs which need to be moved. Items in the LIS maintain their relative order — only items outside the LIS need REMOVE+INSERT. Example: moving last element to front [A,B,C,D,E] → [E,A,B,C,D]: - Greedy: 4 REMOVEs + 5 INSERTs = 9 mutations - LIS: LIS=[A,B,C,D], only E moves = 1 REMOVE + 1 INSERT = 2 mutations The LIS algorithm is O(n log n) time, O(n) space. Since average child count is <10, the position mapping uses linear scan instead of hash tables. Guarded by `useLISAlgorithmInDifferentiator` feature flag (default off). Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D96334873
c0e2626 to
204e70a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
The current Differentiator Stage 4 uses a greedy two-pointer algorithm to
reconcile reordered children. When children are shuffled, it produces excessive
REMOVE+INSERT pairs because it doesn't find the minimal edit.
This adds an alternative code path that uses Longest Increasing Subsequence
(LIS) to identify which children can stay in place vs which need to be moved.
Items in the LIS maintain their relative order — only items outside the LIS
need REMOVE+INSERT.
Example: moving last element to front [A,B,C,D,E] → [E,A,B,C,D]:
The LIS algorithm is O(n log n) time, O(n) space. Since average child count
is <10, the position mapping uses linear scan instead of hash tables.
Guarded by
useLISAlgorithmInDifferentiatorfeature flag (default off).Changelog: [Internal]
Reviewed By: sammy-SC
Differential Revision: D96334873