chore: using micro diff for js objects instead of deepDiff (#32581)

## Description
Using micro diff instead of deepDiff for diffing jsobjects in
setupUpdateTree. Have observed a 33% reduction in webworker scripting
through this on a customer's application.

Fixes #15953

> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/8644903634>
> Commit: f5e4c0fb7d4ebba7c35f03c1cee079b53712cc3c
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8644903634&attempt=2"
target="_blank">Click here!</a>

<!-- end of auto-generated comment: Cypress test results  -->
This commit is contained in:
Vemparala Surya Vamsi 2024-04-11 17:27:30 +05:30 committed by GitHub
parent 271dca0296
commit cfd6cc8fce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 6 deletions

View File

@ -146,6 +146,7 @@
"marked": "^4.0.18", "marked": "^4.0.18",
"memoize-one": "^6.0.0", "memoize-one": "^6.0.0",
"micro-memoize": "^4.0.10", "micro-memoize": "^4.0.10",
"microdiff": "^1.4.0",
"moment": "2.29.4", "moment": "2.29.4",
"moment-timezone": "^0.5.35", "moment-timezone": "^0.5.35",
"nanoid": "^2.0.4", "nanoid": "^2.0.4",

View File

@ -992,3 +992,30 @@ export const isNotEntity = (entity: DataTreeEntity) => {
export const isEntityAction = (entity: DataTreeEntity) => { export const isEntityAction = (entity: DataTreeEntity) => {
return isAction(entity); return isAction(entity);
}; };
export const convertMicroDiffToDeepDiff = (
microDiffDifferences: Record<string, any>[],
) =>
microDiffDifferences.map((v: Record<string, any>) => {
const { oldValue, path, type, value } = v;
//convert microDiff format to deepDiff format
if (type === "CREATE") {
return {
kind: "N",
path,
rhs: value,
};
}
if (type === "REMOVE") {
return {
kind: "D",
path,
lhs: oldValue,
};
}
return {
kind: "E",
path,
lhs: oldValue,
rhs: value,
};
});

View File

@ -37,6 +37,7 @@ import type {
import { EvaluationSubstitutionType } from "entities/DataTree/dataTreeFactory"; import { EvaluationSubstitutionType } from "entities/DataTree/dataTreeFactory";
import { ENTITY_TYPE } from "@appsmith/entities/DataTree/types"; import { ENTITY_TYPE } from "@appsmith/entities/DataTree/types";
import type { DataTreeDiff } from "@appsmith/workers/Evaluation/evaluationUtils"; import type { DataTreeDiff } from "@appsmith/workers/Evaluation/evaluationUtils";
import { convertMicroDiffToDeepDiff } from "@appsmith/workers/Evaluation/evaluationUtils";
import { import {
addDependantsOfNestedPropertyPaths, addDependantsOfNestedPropertyPaths,
@ -127,6 +128,7 @@ import { DependencyMapUtils } from "entities/DependencyMap/DependencyMapUtils";
import { isWidgetActionOrJsObject } from "@appsmith/entities/DataTree/utils"; import { isWidgetActionOrJsObject } from "@appsmith/entities/DataTree/utils";
import DataStore from "workers/Evaluation/dataStore"; import DataStore from "workers/Evaluation/dataStore";
import { updateTreeWithData } from "workers/Evaluation/dataStore/utils"; import { updateTreeWithData } from "workers/Evaluation/dataStore/utils";
import microDiff from "microdiff";
import { import {
profileFn, profileFn,
type WebworkerSpanData, type WebworkerSpanData,
@ -501,7 +503,6 @@ export default class DataTreeEvaluator {
//get difference in js collection body to be parsed //get difference in js collection body to be parsed
const oldUnEvalTreeJSCollections = getJSEntities(this.oldUnEvalTree); const oldUnEvalTreeJSCollections = getJSEntities(this.oldUnEvalTree);
const localUnEvalTreeJSCollection = getJSEntities(localUnEvalTree); const localUnEvalTreeJSCollection = getJSEntities(localUnEvalTree);
const jsDifferences: Diff< const jsDifferences: Diff<
Record<string, JSActionEntity>, Record<string, JSActionEntity>,
Record<string, JSActionEntity> Record<string, JSActionEntity>
@ -509,12 +510,13 @@ export default class DataTreeEvaluator {
"SetupUpdateTree.Diff1", "SetupUpdateTree.Diff1",
undefined, undefined,
webworkerTelemetry, webworkerTelemetry,
() => { () =>
return ( convertMicroDiffToDeepDiff(
diff(oldUnEvalTreeJSCollections, localUnEvalTreeJSCollection) || [] microDiff(oldUnEvalTreeJSCollections, localUnEvalTreeJSCollection) ||
); [],
}, ),
); );
const jsTranslatedDiffs = flatten( const jsTranslatedDiffs = flatten(
jsDifferences.map((diff) => jsDifferences.map((diff) =>
translateDiffEventToDataTreeDiffEvent(diff, localUnEvalTree), translateDiffEventToDataTreeDiffEvent(diff, localUnEvalTree),

View File

@ -13314,6 +13314,7 @@ __metadata:
marked: ^4.0.18 marked: ^4.0.18
memoize-one: ^6.0.0 memoize-one: ^6.0.0
micro-memoize: ^4.0.10 micro-memoize: ^4.0.10
microdiff: ^1.4.0
moment: 2.29.4 moment: 2.29.4
moment-timezone: ^0.5.35 moment-timezone: ^0.5.35
msw: ^0.28.0 msw: ^0.28.0
@ -24707,6 +24708,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"microdiff@npm:^1.4.0":
version: 1.4.0
resolution: "microdiff@npm:1.4.0"
checksum: 4cae2ec4d0540b65656837a7c47a17d6428a1be2909d268a579921183c9c21a86e0dfa0c8ade8c60f9127887783a17d54ce7be16d5556708a0e58312bca8803d
languageName: node
linkType: hard
"micromatch@npm:4.0.5, micromatch@npm:^4.0.0, micromatch@npm:^4.0.2, micromatch@npm:^4.0.4, micromatch@npm:^4.0.5": "micromatch@npm:4.0.5, micromatch@npm:^4.0.0, micromatch@npm:^4.0.2, micromatch@npm:^4.0.4, micromatch@npm:^4.0.5":
version: 4.0.5 version: 4.0.5
resolution: "micromatch@npm:4.0.5" resolution: "micromatch@npm:4.0.5"