Add yield intervals for diffing and hydrating processes

- Introduced `DIFF_YIELD_INTERVAL` and `HYDRATE_YIELD_INTERVAL` constants to manage execution pacing during the diffing and hydrating processes, respectively.
- Implemented logic to pause execution every specified interval to improve performance and prevent potential blocking in long-running operations.
- Enhanced the `diff` and `hydrate` functions to track and yield based on their respective counts, ensuring smoother operation during intensive tasks.

These changes aim to enhance the responsiveness of the system during heavy processing tasks by introducing controlled yielding mechanisms.
This commit is contained in:
Joe 2026-02-19 01:49:13 -06:00
parent b85c5f5ec7
commit 354d4c8b21
2 changed files with 18 additions and 0 deletions

View file

@ -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]

View file

@ -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