From 354d4c8b2132c02bb0f44530e4e4fb39c2767d7c Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 19 Feb 2026 01:49:13 -0600 Subject: [PATCH] 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. --- plugin/src/Reconciler/diff.lua | 8 ++++++++ plugin/src/Reconciler/hydrate.lua | 10 ++++++++++ 2 files changed, 18 insertions(+) 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