PromucFlow_constructor/app/client/src/sagas/EvaluationSaga.utils.ts
Vemparala Surya Vamsi 87fd2eb9f4
chore: send serialised updated and using klona/json instead of klona (#27319)
## Description

- We are no longer performing JSON.stringify(JSON.parse(value)) to
clone, clean up undefined values and serialised bigInt.
- We are performing deepClones using klona/json which is much faster and
later we perform the serialisation on the diff.
- We are sending serialised updated to the main thread and it is parsed
on the main thread, this helps in reducing structuredClone cost of
sending unserialised objects.
- Noticed a reduction of worker thread latency by about 75% and doubled
the databound our app can handle.

#### PR fixes following issue(s)
Fixes #26130

#### Type of change
- Chore (housekeeping or task changes that don't impact user perception)

## Testing
>
#### How Has This Been Tested?

- [x] Manual
- [x] JUnit
- [ ] Jest
- [ ] Cypress
>
>
#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [x] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [x] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-09-26 17:44:20 +05:30

41 lines
1.1 KiB
TypeScript

import log from "loglevel";
import type { DiffWithReferenceState } from "workers/Evaluation/helpers";
export const parseUpdatesAndDeleteUndefinedUpdates = (
updates: string,
): DiffWithReferenceState[] => {
let parsedUpdates = [];
try {
//Parse updates from a string
parsedUpdates = JSON.parse(updates);
} catch (e) {
log.error("Failed to parse updates", e, updates);
return [];
}
//delete all undefined properties from the state
const { deleteUpdates, regularUpdates } = parsedUpdates.reduce(
(acc: any, curr: any) => {
const { kind, path, rhs } = curr;
if (rhs === undefined) {
//ignore any new undefined updates to the state if the value is undefined
if (kind === "N") {
return acc;
}
//convert undefined updates to delete updates
if (kind === "E") {
acc.deleteUpdates.push({ kind: "D", path });
return acc;
}
}
acc.regularUpdates.push(curr);
return acc;
},
{ regularUpdates: [], deleteUpdates: [] },
);
const consolidatedUpdates = [...regularUpdates, ...deleteUpdates];
return consolidatedUpdates;
};