diff --git a/plugin/src/Reconciler/diff.lua b/plugin/src/Reconciler/diff.lua index 8e5d149d..95e8a25a 100644 --- a/plugin/src/Reconciler/diff.lua +++ b/plugin/src/Reconciler/diff.lua @@ -50,6 +50,8 @@ local function shouldDeleteChild(virtualInstance, childInstance) return false end +local DIFF_YIELD_INTERVAL = 1000 + local function diff(instanceMap, virtualInstances, rootId, serverInfo) local patch = { removed = {}, @@ -57,6 +59,8 @@ local function diff(instanceMap, virtualInstances, rootId, serverInfo) updated = {}, } + local diffCount = 0 + -- Build a lookup table for visible services (for ignoreHiddenServices check) local visibleServicesSet: { [string]: boolean } = {} if serverInfo and serverInfo.ignoreHiddenServices and serverInfo.visibleServices then @@ -78,6 +82,10 @@ local function diff(instanceMap, virtualInstances, rootId, serverInfo) -- Internal recursive kernel for diffing an instance with the given ID. local function diffInternal(id) + diffCount += 1 + if diffCount % DIFF_YIELD_INTERVAL == 0 then + task.wait() + end local virtualInstance = virtualInstances[id] local instance = instanceMap.fromIds[id] diff --git a/plugin/src/Reconciler/hydrate.lua b/plugin/src/Reconciler/hydrate.lua index 631c042a..e434483d 100644 --- a/plugin/src/Reconciler/hydrate.lua +++ b/plugin/src/Reconciler/hydrate.lua @@ -13,11 +13,21 @@ local Log = require(Packages.Log) local invariant = require(script.Parent.Parent.invariant) local Matching = require(script.Parent.matching) +local HYDRATE_YIELD_INTERVAL = 1000 + local function hydrate(instanceMap, virtualInstances, rootId, rootInstance, session) if not session then session = Matching.newSession() end + if not session.hydrateCount then + session.hydrateCount = 0 + end + session.hydrateCount += 1 + if session.hydrateCount % HYDRATE_YIELD_INTERVAL == 0 then + task.wait() + end + local virtualInstance = virtualInstances[rootId] if virtualInstance == nil then