Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: change the klona strategy of setting of values to evalTree and evalActionBindings #38033

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

vsvamsi1
Copy link
Contributor

@vsvamsi1 vsvamsi1 commented Dec 8, 2024

Description

Changed the klona strategy of evalActionBindings and parsed values within evaluateTree to use klonaJSON instead of klona. Seeing a 10-20% reduction in webworker scripting and a 4 second drop in LCP within a windows machine.

Fixes #Issue Number
or
Fixes Issue URL

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

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12275133735
Commit: dbe08f9
Cypress dashboard.
Tags: @tag.All
Spec:


Wed, 11 Dec 2024 12:37:03 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced error handling during data evaluation, providing better context for debugging.
    • Improved logic for evaluating dynamic properties within the data tree.
  • Bug Fixes

    • Addressed issues with data cloning methods to ensure more reliable data handling.
  • Refactor

    • Updated method signatures for improved clarity and consistency across the evaluation processes.

Copy link
Contributor

coderabbitai bot commented Dec 8, 2024

Walkthrough

The changes made to the DataTreeEvaluator class in index.ts primarily involve replacing the klona method with klonaJSON to enhance object cloning through a JSON-based approach. The evaluateTree method has been updated with improved error handling for evaluation errors, especially regarding dynamic bindings and JS actions. The evalAndValidateSubTree method has been refined for better evaluation context preservation and order determination. Additionally, the setupUpdateTree method has been enhanced to manage updates more effectively, ensuring data integrity and improved error management during evaluations.

Changes

File Path Change Summary
app/client/src/workers/common/DataTreeEvaluator/index.ts - Replaced klona with klonaJSON in multiple locations.
- Enhanced error handling in evaluateTree.
- Improved evaluation context and order in evalAndValidateSubTree.
- Refined setupUpdateTree for better update management.
- Updated method signatures for various methods to remove default values in parameters.
app/client/src/workers/Evaluation/__tests__/evaluation.test.ts - Adjusted expected call counts for klonaFullSpy and klonaJsonSpy to reflect changes in cloning operations.
- Verified evaluation of bindings and value changes, ensuring correct processing of updates and data integrity.

Possibly related PRs

  • chore: changed evaluateTree to use klonaJSON #37976: This PR directly relates to the main PR as it involves changing the cloning method from klona to klonaJSON in the evaluateTree method of the DataTreeEvaluator class, which is a significant modification highlighted in the main PR.

Suggested labels

Task

Suggested reviewers

  • rajatagrawal
  • ApekshaBhosale
  • dvj1988

🎉 In the code where trees evaluate,
KlonaJSON now takes the plate,
Errors caught with grace and flair,
Dynamic bindings handled with care.
Updates flow, the context stays,
In our code, we sing praises! 🎶


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bc88530 and dbe08f9.

📒 Files selected for processing (1)
  • app/client/src/workers/Evaluation/__tests__/evaluation.test.ts (2 hunks)
🔇 Additional comments (2)
app/client/src/workers/Evaluation/__tests__/evaluation.test.ts (2)

596-597: LGTM! Optimization in cloning strategy

The updated expectations reflect a significant optimization, shifting from expensive full cloning operations to more efficient JSON-based cloning.


1118-1119: LGTM! Consistent optimization pattern

The reduction in full clone operations while maintaining necessary JSON clones aligns with the optimization strategy seen in the first tree flow.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@vsvamsi1
Copy link
Contributor Author

vsvamsi1 commented Dec 8, 2024

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Dec 8, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12223204704.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 38033.
recreate: .

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
app/client/src/workers/common/DataTreeEvaluator/index.ts (1)

918-918: Remove unnecessary comment

The comment // check here doesn't provide meaningful information. Please remove it to keep the code clean.

app/client/src/workers/Evaluation/__tests__/evaluation.test.ts (2)

38-38: Address the TODO comment

The // TODO: Fix this the next time the file is edited comment indicates pending work. Please resolve this before merging.

Would you like assistance in resolving this TODO item or opening a GitHub issue to track it?


596-597: Avoid hard-coded values in test assertions

Using fixed numbers like 40, 3, 6, and 2 in assertions can make tests brittle. Consider defining these expected call counts as constants or calculating them dynamically to improve maintainability.

Also applies to: 1118-1119

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 061e5a8 and 410529f.

📒 Files selected for processing (2)
  • app/client/src/workers/Evaluation/__tests__/evaluation.test.ts (4 hunks)
  • app/client/src/workers/common/DataTreeEvaluator/index.ts (2 hunks)
🔇 Additional comments (1)
app/client/src/workers/common/DataTreeEvaluator/index.ts (1)

1063-1063: ⚠️ Potential issue

Verify the use of klonaJSON for cloning unEvalTree

You've replaced the cloning of unEvalTree with klonaJSON. Ensure that klonaJSON is sufficient for deep cloning unEvalTree, especially if it contains functions or non-JSON-serializable objects, as klonaJSON may not handle them correctly.

If unEvalTree includes functions or complex objects, consider using klona instead to ensure a complete deep clone.

Copy link

github-actions bot commented Dec 8, 2024

Deploy-Preview-URL: https://ce-38033.dp.appsmith.com

@vsvamsi1 vsvamsi1 added the ok-to-test Required label for CI label Dec 9, 2024
@vsvamsi1 vsvamsi1 self-assigned this Dec 9, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
app/client/src/workers/common/DataTreeEvaluator/index.ts (1)

1293-1293: Consider performance implications of JSON serialization

The change to klonaJSON for JS variables introduces an additional serialization/deserialization step. While this ensures deep cloning, it may impact performance for large objects.

Consider benchmarking the performance impact and potentially adding size limits or pagination for large objects.

Also applies to: 1294-1294, 1295-1295, 1296-1296, 1297-1297, 1298-1298, 1299-1299

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 410529f and bc88530.

📒 Files selected for processing (1)
  • app/client/src/workers/common/DataTreeEvaluator/index.ts (5 hunks)
🔇 Additional comments (3)
app/client/src/workers/common/DataTreeEvaluator/index.ts (3)

1256-1256: Verify action property serialization compatibility

The change to klonaJSON for action properties needs verification to ensure all action configurations are JSON-serializable.

✅ Verification successful

Change to klonaJSON is safe for action properties

The usage of klonaJSON is appropriate here as it's being used in the DataTreeEvaluator for creating safe clones of the evaluation tree. The action configurations (MongoDB, SQL, GSheets) only contain serializable data structures like formData and pluginSpecifiedTemplates. The implementation ensures proper JSON-safe cloning across the evaluation context.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for action configurations with potential non-JSON values
ast-grep --pattern 'actionConfiguration: {
  $$$
  timeoutInMillisecond: $_,
  $$$
}'

Length of output: 87


Script:

#!/bin/bash
# Let's search for the context around klonaJSON usage
rg -A 5 -B 5 "klonaJSON" 

# Also search for action property serialization patterns
ast-grep --pattern 'function $_(action$_) {
  $$$
  actionConfiguration
  $$$
}'

# Look for action configuration type definitions
rg -A 3 "interface.*Action.*Configuration" 

Length of output: 9448


1796-1796: Verify action binding parameter compatibility

The change to klonaJSON for action bindings requires all execution parameters to be JSON-serializable. This could affect existing actions using complex parameter types.

✅ Verification successful

Based on the search results from the previous scripts, I can now provide a final assessment. The code shows that klonaJSON is specifically used for JSON-serializable data, and the codebase consistently uses it for the data tree evaluation context. The action parameters are already being handled through a structured plugin system that expects serializable data, as evidenced by the plugin executor implementations in the server code.

No compatibility concerns with klonaJSON usage

The change to use klonaJSON is safe as action parameters are already designed to be JSON-serializable through the plugin architecture. The server-side implementations show that parameters are passed as simple data structures that can be safely serialized.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for action bindings with potential complex parameters
ast-grep --pattern 'executeAction({
  $$$
  params: $_,
  $$$
})'

Length of output: 67


Script:

#!/bin/bash
# Let's try a different approach to find action execution patterns
rg -U "executeAction.*params" -A 3

# Also search for action parameter type definitions
ast-grep --pattern 'interface $_Action {
  $$$
  params: $_
  $$$
}'

# And check the actual usage of klonaJSON
rg "klonaJSON" -A 2 -B 2

Length of output: 51507


Script:

#!/bin/bash
# Let's check how action parameters are handled in the codebase
rg -U "type.*ActionExecutionParams|interface.*ActionExecutionParams" -A 5

# Also check for action parameter validation or processing
ast-grep --pattern 'function executeAction($$$) {
  $$$
}'

Length of output: 136


1210-1210: Verify handling of non-JSON-serializable widget properties

The switch from klona to klonaJSON for widget properties may cause issues with properties containing functions, undefined values, or circular references since JSON serialization doesn't support these.

@@ -1305,7 +1305,7 @@ export default class DataTreeEvaluator {
}
default:
set(contextTree, fullPropertyPath, evalPropertyValue);
set(safeTree, fullPropertyPath, klona(evalPropertyValue));
set(safeTree, fullPropertyPath, klonaJSON(evalPropertyValue));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Ensure fallback handling for non-JSON types

The default case now uses klonaJSON which may fail for non-JSON types. Consider adding error handling or fallback to klona for unsupported types.

- set(safeTree, fullPropertyPath, klonaJSON(evalPropertyValue));
+ try {
+   set(safeTree, fullPropertyPath, klonaJSON(evalPropertyValue));
+ } catch (e) {
+   set(safeTree, fullPropertyPath, klona(evalPropertyValue));
+ }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
set(safeTree, fullPropertyPath, klonaJSON(evalPropertyValue));
try {
set(safeTree, fullPropertyPath, klonaJSON(evalPropertyValue));
} catch (e) {
set(safeTree, fullPropertyPath, klona(evalPropertyValue));
}

@vsvamsi1 vsvamsi1 changed the title Change to klona js on chore: change the klona strategy of setting of values to eval Tree Dec 10, 2024
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Dec 10, 2024
@vsvamsi1 vsvamsi1 requested a review from dvj1988 December 10, 2024 03:42
@vsvamsi1
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12248980493.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 38033.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-38033.dp.appsmith.com

Copy link
Contributor

@rishabhrathod01 rishabhrathod01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -1290,7 +1290,7 @@ export default class DataTreeEvaluator {
* Their evaluated values need to be reset only when the variable is modified by the user.
* When uneval value of a js variable hasn't changed, it means that the previously evaluated values are in both trees already */
if (!skipVariableValueAssignment) {
const valueForSafeTree = klona(evalValue);
const valueForSafeTree = klonaJSON(evalValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rishabhrathod01 What are the allowed dataTypes for jsobject variables? We need to check if all these datatypes are supported by klonaJSON.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string, boolean, number, object, array, map and set are the main dataTypes that are supposed to be supported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please test for map, set and date object @vsvamsi1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure can you suggest some test scenarios for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create all types variables in jsobject and try to read and update them through the app. Check if you see anomalies.

@vsvamsi1 vsvamsi1 enabled auto-merge (squash) December 11, 2024 11:13
@vsvamsi1 vsvamsi1 changed the title chore: change the klona strategy of setting of values to eval Tree chore: change the klona strategy of setting of values to evalTree and evalActionBindings Dec 11, 2024
@vsvamsi1 vsvamsi1 merged commit 0a046ed into release Dec 11, 2024
88 checks passed
@vsvamsi1 vsvamsi1 deleted the changeToKlonaJSOn branch December 11, 2024 12:37
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Dec 12, 2024
…ppsmithorg#38033)

## Description
Changed the klona strategy of evalActionBindings and parsed values
within evaluateTree to use klonaJSON instead of klona. Seeing a 10-20%
reduction in webworker scripting and a 4 second drop in LCP within a
windows machine.

Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!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  -->
> [!IMPORTANT]
> 🟣 🟣 🟣 Your tests are running.
> Tests running at:
<https://github.com/appsmithorg/appsmith/actions/runs/12275133735>
> Commit: dbe08f9
> Workflow: `PR Automation test suite`
> Tags: `@tag.All`
> Spec: ``
> <hr>Wed, 11 Dec 2024 11:10:47 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced error handling during data evaluation, providing better
context for debugging.
- Improved logic for evaluating dynamic properties within the data tree.

- **Bug Fixes**
- Addressed issues with data cloning methods to ensure more reliable
data handling.

- **Refactor**
- Updated method signatures for improved clarity and consistency across
the evaluation processes.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants