mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 14:01:37 +00:00
Refactor encoding logic in ChangeBatcher and improve matching depth handling
- Simplified the `isReadable` condition in `encodeService` for better readability. - Updated the `ServiceChunk` structure to conditionally include properties and references only if they exist, enhancing data efficiency. - Introduced a `MAX_SCORING_DEPTH` constant in the matching module to limit recursion depth, improving performance and preventing potential stack overflow issues. - Refactored the `computePairCost` and `matchChildren` functions to incorporate the new depth parameter, ensuring accurate cost calculations during matching. These changes enhance the clarity and efficiency of the encoding and matching processes, contributing to overall performance improvements.
This commit is contained in:
parent
e0fd9077e8
commit
a823db0297
5 changed files with 34 additions and 21 deletions
|
|
@ -25,6 +25,7 @@ local RbxDom = require(Packages.RbxDom)
|
|||
local trueEquals = require(script.Parent.trueEquals)
|
||||
|
||||
local UNMATCHED_PENALTY = 10000
|
||||
local MAX_SCORING_DEPTH = 3
|
||||
|
||||
-- ================================================================
|
||||
-- Types
|
||||
|
|
@ -341,7 +342,8 @@ local function computePairCost(
|
|||
virtualId: string,
|
||||
studioInstance: Instance,
|
||||
virtualInstances: VirtualInstances,
|
||||
bestSoFar: number
|
||||
bestSoFar: number,
|
||||
depth: number
|
||||
): number
|
||||
local vc = session.costCache[virtualId]
|
||||
if vc then
|
||||
|
|
@ -365,7 +367,7 @@ local function computePairCost(
|
|||
local sCache = cacheStudio(studioInstance, classKeys, vCache.extraProps, refPropNames)
|
||||
|
||||
local cost = countOwnDiffs(vCache, sCache, classKeys)
|
||||
if cost >= bestSoFar then
|
||||
if cost >= bestSoFar or depth >= MAX_SCORING_DEPTH then
|
||||
return cost
|
||||
end
|
||||
|
||||
|
|
@ -378,8 +380,15 @@ local function computePairCost(
|
|||
elseif #studioKids == 0 then
|
||||
cost += #validVChildren * UNMATCHED_PENALTY
|
||||
else
|
||||
local childResult =
|
||||
matchChildren(session, validVChildren, studioKids, virtualInstances, virtualId, studioInstance)
|
||||
local childResult = matchChildren(
|
||||
session,
|
||||
validVChildren,
|
||||
studioKids,
|
||||
virtualInstances,
|
||||
virtualId,
|
||||
studioInstance,
|
||||
depth + 1
|
||||
)
|
||||
cost += childResult.totalCost
|
||||
end
|
||||
end
|
||||
|
|
@ -400,8 +409,10 @@ matchChildren = function(
|
|||
studioChildren: { Instance },
|
||||
virtualInstances: VirtualInstances,
|
||||
parentVirtualId: string?,
|
||||
parentStudioInstance: Instance?
|
||||
parentStudioInstance: Instance?,
|
||||
depth: number?
|
||||
): MatchResult
|
||||
depth = depth or 0
|
||||
if parentVirtualId and parentStudioInstance then
|
||||
local pc = session.matchCache[parentVirtualId]
|
||||
if pc then
|
||||
|
|
@ -522,7 +533,7 @@ matchChildren = function(
|
|||
pairIdx += 1
|
||||
local cost = countOwnDiffs(vCache, sCache, classKeys)
|
||||
|
||||
if cost < bestSoFar then
|
||||
if cost < bestSoFar and depth < MAX_SCORING_DEPTH then
|
||||
local validVChildren = vCache.validChildren
|
||||
local studioKids = sCache.children
|
||||
|
||||
|
|
@ -538,7 +549,8 @@ matchChildren = function(
|
|||
studioKids,
|
||||
virtualInstances,
|
||||
virtualChildren[vi],
|
||||
sCache.instance
|
||||
sCache.instance,
|
||||
depth + 1
|
||||
)
|
||||
cost += childResult.totalCost
|
||||
end
|
||||
|
|
@ -591,7 +603,7 @@ matchChildren = function(
|
|||
|
||||
local totalCost = 0
|
||||
for _, pair in ipairs(matched) do
|
||||
totalCost += computePairCost(session, pair.virtualId, pair.studioInstance, virtualInstances, math.huge)
|
||||
totalCost += computePairCost(session, pair.virtualId, pair.studioInstance, virtualInstances, math.huge, depth)
|
||||
end
|
||||
totalCost += (#unmatchedVirtual + #unmatchedStudio) * UNMATCHED_PENALTY
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue