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: debounce handle action updates #38349

Closed
wants to merge 6 commits into from
Closed

chore: debounce handle action updates #38349

wants to merge 6 commits into from

Conversation

vsvamsi1
Copy link
Contributor

@vsvamsi1 vsvamsi1 commented Dec 24, 2024

Description

Debounced handleActionUpdate actions together with bufferedActions, this has reduced the webworker scripting and LCP by about 25-30% on 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

Warning

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12515902433
Commit: 41ec14d
Cypress dashboard.
Tags: @tag.All
Spec:
It seems like no tests ran 😔. We are not able to recognize it, please check workflow here.


Mon, 30 Dec 2024 04:30:58 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 Redux action type for handling updates to action data.
    • Added an interface to manage buffered actions, improving action processing efficiency.
  • Bug Fixes

    • Enhanced test cases for evaluation processes, ensuring accurate representation of buffered actions and logging levels.
  • Chores

    • Updated type definitions for improved type safety in action data handling.
    • Made actionDataPayload type accessible across modules for enhanced usability.
    • Removed unnecessary function related to action data updates, simplifying control flow.

@vsvamsi1 vsvamsi1 marked this pull request as draft December 24, 2024 11:30
Copy link
Contributor

coderabbitai bot commented Dec 24, 2024

Walkthrough

The pull request introduces changes to action data handling across multiple files in the application. The modifications primarily focus on improving the management of action updates, including exporting the actionDataPayload type, adding a new Redux action type, and refactoring the evaluation saga to more efficiently process and buffer action updates. The changes streamline the action data flow and reduce unnecessary evaluations.

Changes

File Change Summary
app/client/src/actions/pluginActionActions.ts Exported actionDataPayload type for broader accessibility
app/client/src/ce/actions/evaluationActionsList.ts Added ReduxActionTypes.UPDATE_ACTION_DATA to EVALUATE_REDUX_ACTIONS
app/client/src/sagas/ActionExecution/PluginActionSaga.ts Removed handleUpdateActionData function and its associated saga watcher
app/client/src/sagas/EvaluationsSaga.ts Added BUFFERED_ACTION interface, updated import types, and modified action handling logic
app/client/src/sagas/EvaluationsSaga.test.ts Enhanced tests for evaluateTreeSaga and evalQueueBuffer functions

Suggested labels

Bug, Performance, Task, Query & JS Pod, JS Objects, Javascript Product

Suggested reviewers

  • ankitakinger
  • hetunandu
  • sharat87

Poem

🚀 Code flows like a river's might,
Actions dance in digital light,
Sagas weave their magic spell,
Refactoring tales we'll tell!
Efficiency blooms, clean and bright 🌟

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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. (Beta)
  • @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 vsvamsi1 added the ok-to-test Required label for CI label Dec 24, 2024
@vsvamsi1 vsvamsi1 changed the title debounce handle action updates chore: debounce handle action updates Dec 26, 2024
@vsvamsi1 vsvamsi1 marked this pull request as ready for review December 26, 2024 10:31
@vsvamsi1 vsvamsi1 self-assigned this Dec 26, 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 26, 2024
@vsvamsi1 vsvamsi1 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Dec 26, 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

🧹 Nitpick comments (3)
app/client/src/sagas/EvaluationsSaga.ts (3)

543-547: Consider a more conventional interface name.

Using BUFFERED_ACTION as an interface name is fine but slightly inconsistent with typical TypeScript naming (e.g., BufferedAction).

You might consider renaming for clarity:

-interface BUFFERED_ACTION {
+interface BufferedAction {
  hasDebouncedHandleUpdate: boolean;
  hasBufferedAction: boolean;
  actionDataPayloadConsolidated: actionDataPayload[];
}

550-553: Good initialization of local state.

Storing flags and consolidated payload in separate variables is clear. A possible improvement would be grouping them into a config object for better structure, but this is optional.

-let hasDebouncedHandleUpdate = false;
-let hasBufferedAction = false;
-let actionDataPayloadConsolidated: actionDataPayload = [];
+let bufferedState = {
+  hasDebouncedHandleUpdate: false,
+  hasBufferedAction: false,
+  actionDataPayloadConsolidated: [] as actionDataPayload,
+};

600-615: Use optional chaining for cleaner checks.

- if (actionDataPayload && actionDataPayload.length) {
+ if (actionDataPayload?.length) {

This minor refinement can reduce complexity. Otherwise, the logic for consolidating actionDataPayload is sound.

🧰 Tools
🪛 Biome (1.9.4)

[error] 604-604: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6905aa9 and 73e15b6.

📒 Files selected for processing (4)
  • app/client/src/actions/pluginActionActions.ts (1 hunks)
  • app/client/src/ce/actions/evaluationActionsList.ts (1 hunks)
  • app/client/src/sagas/ActionExecution/PluginActionSaga.ts (0 hunks)
  • app/client/src/sagas/EvaluationsSaga.ts (5 hunks)
💤 Files with no reviewable changes (1)
  • app/client/src/sagas/ActionExecution/PluginActionSaga.ts
🧰 Additional context used
🪛 Biome (1.9.4)
app/client/src/sagas/EvaluationsSaga.ts

[error] 604-604: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (8)
app/client/src/ce/actions/evaluationActionsList.ts (1)

111-111: Great addition!

This newly introduced UPDATE_ACTION_DATA action type seamlessly extends the set of Redux actions that trigger evaluations. It appears well-integrated with the rest of the file.

app/client/src/actions/pluginActionActions.ts (1)

391-391: Exporting the type is a good move!

Converting actionDataPayload to an exported type is beneficial for reuse across multiple modules. Make sure to verify that existing references now import it correctly.

✅ Verification successful

Type is correctly imported and used across the codebase

The exported actionDataPayload type is properly imported and used in EvaluationsSaga.ts. All references to this type are consistent with its definition in pluginActionActions.ts. No issues found with the type export.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify all references to actionDataPayload
rg -A 3 $'actionDataPayload'

Length of output: 5084

app/client/src/sagas/EvaluationsSaga.ts (6)

97-101: Imports look correct and consistent!

Importing the newly exported types and existing executeJSUpdates function aligns with the recent additions in pluginActionActions.ts.


568-575: Resetting variables is handled correctly.

You’re effectively clearing out the buffered state for the next cycle. This is consistent with re-initializing local variables once their usage completes.


578-580: Consolidation fields are well-structured.

Destructuring into the return object ensures clarity for the calling code. Nicely done.


804-813: Direct saga call for UPDATE_ACTION_DATA.

This succinctly handles action-data updates before continuing to other logic. Looks appropriate for your architecture.


815-826: Clear separation of non-buffered actions.

This neatly funnels non-buffered actions into the main evaluation flow. The branching logic is simple and easy to follow.


827-853: Nicely handles buffered debounced actions.

Collecting update payloads and deferring them until a single shot is efficient. Well-structured approach to reduce repeated evaluations.

@vsvamsi1 vsvamsi1 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Dec 26, 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

🧹 Nitpick comments (2)
app/client/src/sagas/EvaluationsSaga.test.ts (2)

213-215: Avoid redundant property initialization in multiple places if possible
Since lines 213-215 duplicate the same values as the previous block, factor them out, or use a shared utility if these are consistently repeated.


267-269: Reassess the necessity of actionDataPayloadConsolidated
If future logic is anticipated to populate this array, confirm that the test coverage reflects different states for this property. Otherwise, consider removing it to reduce complexity.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 73e15b6 and 1333a93.

📒 Files selected for processing (1)
  • app/client/src/sagas/EvaluationsSaga.test.ts (4 hunks)
🔇 Additional comments (2)
app/client/src/sagas/EvaluationsSaga.test.ts (2)

193-195: Consider verifying usage and test coverage for newly introduced properties
These properties are great additions to the buffered action state. However, ensure thorough tests confirm that actionDataPayloadConsolidated, hasBufferedAction, and hasDebouncedHandleUpdate accurately reflect their intended behavior under various scenarios.


237-239: Check for consistent updates to the hasDebouncedHandleUpdate flag
Currently, hasDebouncedHandleUpdate is set to false. If this value must reflect whether a debounce occurred, consider adding logic to flip it to true when the debounce condition is triggered.

@vsvamsi1 vsvamsi1 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Dec 26, 2024
Copy link
Contributor

@rajatagrawal rajatagrawal left a comment

Choose a reason for hiding this comment

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

Can we please add test cases for the new logic ?

@vsvamsi1 vsvamsi1 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Dec 27, 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

🧹 Nitpick comments (1)
app/client/src/sagas/EvaluationsSaga.test.ts (1)

279-386: Great test coverage for debouncing functionality!

The new tests thoroughly cover the debouncing scenarios. Consider adding one more test case:

Add a test case for error handling when invalid action data is provided:

test("should handle invalid action data gracefully during debouncing", () => {
  const buffer = evalQueueBuffer();
  
  buffer.put(
    updateActionData([
      {
        entityName: "widget1",
        // missing required fields
        data: { a: 1 }
      }
    ])
  );
  
  const bufferedAction = buffer.take();
  expect(bufferedAction.hasBufferedAction).toBeFalsy();
  expect(bufferedAction.hasDebouncedHandleUpdate).toBeTruthy();
  expect(bufferedAction.actionDataPayloadConsolidated).toEqual([]);
});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc48c06 and 41ec14d.

📒 Files selected for processing (1)
  • app/client/src/sagas/EvaluationsSaga.test.ts (6 hunks)
🔇 Additional comments (2)
app/client/src/sagas/EvaluationsSaga.test.ts (2)

29-29: LGTM!

The import is correctly added for testing the new action data update functionality.


194-196: LGTM! Test coverage looks comprehensive.

The new properties for debounced action handling are consistently added across all test cases, maintaining the test coverage for both existing and new functionality.

Let's verify the test coverage:

Also applies to: 214-216, 238-240, 256-258, 271-273

✅ Verification successful

Test coverage for debounced action handling is comprehensive

The test suite thoroughly covers all scenarios for the new debouncing properties:

  • Default state with empty consolidated payload
  • Multiple action data updates being consolidated
  • Combinations of buffered and debounced actions
  • Various affected JS objects states
  • Both true/false states for hasBufferedAction and hasDebouncedHandleUpdate

The consistent assertions across test cases validate the correct implementation of the new debouncing functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if we have tests for all possible combinations of buffered actions
rg "test\(.*should.*UPDATE_ACTION_DATA.*BUFFERED_ACTION" -A 5

Length of output: 548


Script:

#!/bin/bash
# Let's check for all test cases related to buffered actions and debouncing
rg "test\(.*buffer.*action" -i app/client/src/sagas/EvaluationsSaga.test.ts -A 5

# Also check for any other test cases that might be related to action data updates
rg "test\(.*UPDATE_ACTION_DATA" app/client/src/sagas/EvaluationsSaga.test.ts -A 5

Length of output: 1565


Script:

#!/bin/bash
# Let's check the implementation of these test cases to verify coverage
rg "updateActionData.*BUFFERED_ACTION" app/client/src/sagas/EvaluationsSaga.test.ts -B 5 -A 15

# Also check the test assertions to ensure they verify the new properties
ast-grep --pattern 'expect($_).toEqual({
  $$$
  actionDataPayloadConsolidated: $_,
  hasBufferedAction: $_,
  hasDebouncedHandleUpdate: $_,
  $$$
})'

Length of output: 7500

@vsvamsi1 vsvamsi1 closed this Dec 30, 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 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.

2 participants