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: allKeys computation is constrained by diff #35303

Merged
merged 7 commits into from
Aug 3, 2024
Merged

chore: allKeys computation is constrained by diff #35303

merged 7 commits into from
Aug 3, 2024

Conversation

vsvamsi1
Copy link
Contributor

@vsvamsi1 vsvamsi1 commented Jul 31, 2024

Description

allKeys is previously computed from the complete unevalTree, we used to recursively traverse through the entire unevalTree during each evaluation update cycle. We are optimising this by leveraging the diff which we have previously computed and using the diff to directly update the allKeys result.
When delete based diffs detected are detected we are directly deleting the nodes in the previous allKeys result, for only new nodes we are recursively computing the allKeys for those nodes and merging it back to the previous allKeys result. The time complexity of the solution has improved by limiting iterations to the diff alone instead of computing the entire unevalTree.

Fixes #35386

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/10220298181
Commit: 12b94c3
Cypress dashboard.
Tags: @tag.All
Spec:


Fri, 02 Aug 2024 19:22:32 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new function for dynamic path management based on differential updates.
    • Enhanced data processing in the DataTreeEvaluator class to improve dependency tracking and efficiency.
  • Bug Fixes

    • Improved handling of data tree updates to ensure accurate addition and deletion of paths.
  • Tests

    • Added a comprehensive test suite for the new path management function, verifying accurate response to various data tree changes.

@vsvamsi1 vsvamsi1 requested a review from ApekshaBhosale as a code owner July 31, 2024 03:57
Copy link
Contributor

coderabbitai bot commented Jul 31, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent updates introduce the getAllPathsBasedOnDiffPaths function to the evaluationUtils module, significantly enhancing its capability to manage data paths dynamically based on differential updates. This improvement allows for more efficient handling of additions and deletions within data structures. Additionally, the DataTreeEvaluator class has been modified to leverage this new function, resulting in superior tracking and management of data relationships. Overall, these changes enhance performance and streamline data handling.

Changes

Files Change Summary
app/.../Evaluation/evaluationUtils.ts
app/.../DataTreeEvaluator/index.ts
Introduced getAllPathsBasedOnDiffPaths, which processes diffs to update paths dynamically, enhancing path management logic. Replaced getAllPaths with the new function in DataTreeEvaluator for improved path retrieval based on updates.
app/.../DataTreeEvaluator/utils.test.ts Enhanced the test suite with new tests for getAllPathsBasedOnDiffPaths, covering scenarios like adding, deleting, and editing properties to ensure accurate path updates.

Sequence Diagram(s)

sequenceDiagram
    participant A as Records
    participant B as Diff (DataTreeDiff)
    participant C as Previous Result
    participant D as New Result

    A->>B: Provides data updates
    B->>C: Checks event type (DELETE or NEW)
    C-->>D: Updates paths accordingly
    D-->>C: Returns updated paths
Loading

✨ In the realm of code, changes take flight,
A function emerges, paths shining bright.
With diffs in hand, we dance through the trees,
Managing updates with effortless ease.
So here's to the new and the paths we pave,
In the world of data, we're clever and brave! 🌟


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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 vsvamsi1 self-assigned this Jul 31, 2024
@vsvamsi1 vsvamsi1 marked this pull request as draft July 31, 2024 03:57
@vsvamsi1 vsvamsi1 added the ok-to-test Required label for CI label Jul 31, 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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between de44310 and 6fd3527.

Files selected for processing (2)
  • app/client/src/ce/workers/Evaluation/evaluationUtils.ts (1 hunks)
  • app/client/src/workers/common/DataTreeEvaluator/index.ts (2 hunks)
Additional comments not posted (1)
app/client/src/workers/common/DataTreeEvaluator/index.ts (1)

664-668: Excellent integration of dynamic path management!

The replacement of getAllPaths with getAllPathsBasedOnDiffPaths enhances the function's ability to handle differential updates. However, consider the following improvements:

  1. Error Handling: Ensure that any potential errors from getAllPathsBasedOnDiffPaths are properly handled to prevent unexpected failures.
  2. Performance Monitoring: Monitor the performance impact of this change, especially if the diff array is large. Consider adding logging to track execution time.

Comment on lines 528 to 547
export const getAllPathsBasedOnDiffPaths = (
records: any,
diff: DataTreeDiff[],
previousResult: Record<string, true> = {},
): Record<string, true> => {
const newResult = previousResult;
diff.forEach((curr) => {
const { event, payload } = curr;
if (event === DataTreeDiffEvent.DELETE) {
delete newResult[payload.propertyPath];
}
if (event === DataTreeDiffEvent.NEW) {
const newDataSegments = get(records, payload.propertyPath);
// directly mutates on the result so we don't have to merge it back to the result
getAllPaths(newDataSegments, payload.propertyPath, newResult);
}
});

return newResult;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Great job on implementing dynamic path management!

The function getAllPathsBasedOnDiffPaths is well-structured and handles differential updates effectively. However, consider the following improvements:

  1. Optimize Mutation: Directly mutating newResult can be risky. Consider creating a copy of previousResult to avoid unintended side effects.
  2. Add Comments: Adding comments to explain the logic, especially for the recursive call to getAllPaths, would improve readability.
  3. Error Handling: Include error handling to manage unexpected cases, such as invalid propertyPath or records.
export const getAllPathsBasedOnDiffPaths = (
  records: any,
  diff: DataTreeDiff[],
  previousResult: Record<string, true> = {},
): Record<string, true> => {
  const newResult = { ...previousResult };
  diff.forEach((curr) => {
    const { event, payload } = curr;
    if (event === DataTreeDiffEvent.DELETE) {
      delete newResult[payload.propertyPath];
    }
    if (event === DataTreeDiffEvent.NEW) {
      const newDataSegments = get(records, payload.propertyPath);
      // directly mutates on the result so we don't have to merge it back to the result
      getAllPaths(newDataSegments, payload.propertyPath, newResult);
    }
  });
  return newResult;
};

Committable suggestion was skipped due to low confidence.

@vsvamsi1 vsvamsi1 changed the title Test17 chore: Test17 Jul 31, 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 Jul 31, 2024
@vsvamsi1 vsvamsi1 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jul 31, 2024
@vsvamsi1 vsvamsi1 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jul 31, 2024
@vsvamsi1 vsvamsi1 changed the title chore: Test17 chore: allKeys are constrained by diff Jul 31, 2024
@vsvamsi1 vsvamsi1 changed the title chore: allKeys are constrained by diff chore: allKeys computation is constrained by diff Jul 31, 2024
@sagar-qa007
Copy link
Contributor

@vsvamsi1 Do we have plan for adding unit test cases as well?

@vsvamsi1 vsvamsi1 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Aug 2, 2024
@vsvamsi1 vsvamsi1 marked this pull request as ready for review August 2, 2024 13:28
@vsvamsi1 vsvamsi1 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Aug 2, 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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6fd3527 and 1c7b6df.

Files selected for processing (2)
  • app/client/src/ce/workers/Evaluation/evaluationUtils.ts (1 hunks)
  • app/client/src/workers/common/DataTreeEvaluator/index.ts (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • app/client/src/ce/workers/Evaluation/evaluationUtils.ts
  • app/client/src/workers/common/DataTreeEvaluator/index.ts

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1c7b6df and 1183492.

Files selected for processing (2)
  • app/client/src/ce/workers/Evaluation/evaluationUtils.ts (1 hunks)
  • app/client/src/workers/common/DataTreeEvaluator/utils.test.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/ce/workers/Evaluation/evaluationUtils.ts
Additional context used
Biome
app/client/src/workers/common/DataTreeEvaluator/utils.test.ts

[error] 168-168: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 184-184: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

Additional comments not posted (6)
app/client/src/workers/common/DataTreeEvaluator/utils.test.ts (6)

7-11: Good job updating the imports.

The import statements correctly include DataTreeDiffEvent and getAllPathsBasedOnDiffPaths, which are necessary for the new test suite.


109-109: Excellent addition of the test suite for getAllPathsBasedOnDiffPaths.

The new test suite is well-structured and covers various scenarios, ensuring comprehensive testing of the function.


145-158: Great job on the test case for adding a new widget.

This test case effectively verifies that all paths are generated correctly when a new widget is added.


159-165: Well done on the test case for no diffs.

This test case correctly verifies that allKeys remains unchanged when there are no diffs.


190-216: Great test case for adding a node.

This test case effectively verifies that the correct paths are added when a node is added.


218-241: Well done on the test case for editing a node.

This test case correctly verifies that the correct paths are generated when a node's value changes from a simple primitive to a collection.

Comment on lines 166 to 188
test("should delete the correct paths within allKeys when a node within a widget is deleted", () => {
const deletedWidgetName = produce(initialTree, (draft: any) => {
delete draft.WidgetName.name;
});
const updatedAllKeys = getAllPathsBasedOnDiffPaths(
deletedWidgetName,
[
{
event: DataTreeDiffEvent.DELETE,
payload: {
propertyPath: "WidgetName.name",
},
},
],
// we have to make a copy since allKeys is mutable
{ ...initialAllKeys },
);
const deletedWidgetNameAllKeys = produce(initialAllKeys, (draft: any) => {
delete draft["WidgetName.name"];
});

expect(deletedWidgetNameAllKeys).toEqual(updatedAllKeys);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Good test case for deleting a node, but consider optimizing performance.

This test case correctly verifies that the correct paths are deleted when a node is deleted. However, using the delete operator can impact performance. Consider using an undefined assignment instead.

- delete draft.WidgetName.name;
+ draft.WidgetName.name = undefined;

Similarly, update the deletion in deletedWidgetNameAllKeys:

- delete draft["WidgetName.name"];
+ draft["WidgetName.name"] = undefined;
Tools
Biome

[error] 168-168: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 184-184: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

@vsvamsi1 vsvamsi1 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Aug 2, 2024
rajatagrawal
rajatagrawal previously approved these changes Aug 2, 2024
@vsvamsi1 vsvamsi1 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Aug 2, 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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1183492 and 12b94c3.

Files selected for processing (1)
  • app/client/src/ce/workers/Evaluation/evaluationUtils.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/ce/workers/Evaluation/evaluationUtils.ts

@github-actions github-actions bot added Performance Issues related to performance Task A simple Todo UI Building Product Issues related to the UI Building experience UI Performance Issues related to UI performance labels Aug 2, 2024
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 Performance Issues related to performance skip-changelog Adding this label to a PR prevents it from being listed in the changelog Task A simple Todo UI Building Product Issues related to the UI Building experience UI Performance Issues related to UI performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimise getAllKeys function.
3 participants