From 6c58b40d0e231660bf28a269421f7709817ef256 Mon Sep 17 00:00:00 2001 From: Vemparala Surya Vamsi <121419957+vsvamsi1@users.noreply.github.com> Date: Thu, 28 Mar 2024 15:57:50 +0530 Subject: [PATCH] chore: Capture telemetry around diff and serialise operation (#32124) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Capture telemetry around compute diff between old and new states, also capture the serialise cost of the updates. Fixes #32123 ## Automation /ok-to-test tags="@tag.All" ### :mag: Cypress test results > [!IMPORTANT] > Workflow run: > Commit: `9c1be427190586b155ff5daecfe190f743bacc63` > Cypress dashboard url: Click here! > All cypress tests have passed 🎉🎉🎉 ## Summary by CodeRabbit - **Refactor** - Improved and optimized update generation logic in the evaluation process. - Enhanced handling of undefined values, function properties, and serialization errors, including `BigInt` and `moment` objects. - Ensured more consistent handling of `moment` objects during updates. - **Tests** - Added and modified tests to cover new scenarios in update generation and data manipulation, including handling of `EvaluationError`. --- .../workers/Evaluation/handlers/evalTree.ts | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/app/client/src/workers/Evaluation/handlers/evalTree.ts b/app/client/src/workers/Evaluation/handlers/evalTree.ts index 53651e3e15..de653f9696 100644 --- a/app/client/src/workers/Evaluation/handlers/evalTree.ts +++ b/app/client/src/workers/Evaluation/handlers/evalTree.ts @@ -239,32 +239,40 @@ export function evalTree(request: EvalWorkerSyncRequest) { const jsVarsCreatedEvent = getJSVariableCreatedEvents(jsUpdates); - let updates; - if (isNewTree) { - try { - //for new tree send the whole thing, don't diff at all - updates = serialiseToBigInt([{ kind: "newTree", rhs: dataTree }]); - dataTreeEvaluator?.setPrevState(dataTree); - } catch (e) { - updates = "[]"; - } - isNewTree = false; - } else { - const allUnevalUpdates = unEvalUpdates.map( - (update) => update.payload.propertyPath, - ); + const updates = profileFn( + "diffAndGenerateSerializeUpdates", + undefined, + webworkerTelemetry, + () => { + let updates; + if (isNewTree) { + try { + //for new tree send the whole thing, don't diff at all + updates = serialiseToBigInt([{ kind: "newTree", rhs: dataTree }]); + dataTreeEvaluator?.setPrevState(dataTree); + } catch (e) { + updates = "[]"; + } + isNewTree = false; + } else { + const allUnevalUpdates = unEvalUpdates.map( + (update) => update.payload.propertyPath, + ); - const completeEvalOrder = uniqueOrderUpdatePaths([ - ...allUnevalUpdates, - ...evalOrder, - ]); + const completeEvalOrder = uniqueOrderUpdatePaths([ + ...allUnevalUpdates, + ...evalOrder, + ]); - updates = generateOptimisedUpdatesAndSetPrevState( - dataTree, - dataTreeEvaluator, - completeEvalOrder, - ); - } + updates = generateOptimisedUpdatesAndSetPrevState( + dataTree, + dataTreeEvaluator, + completeEvalOrder, + ); + } + return updates; + }, + ); const evalTreeResponse: EvalTreeResponseData = { updates,