Skip to content

chore: batching updates for a few widgets to reduce rerenders#35594

Merged
vsvamsi1 merged 1 commit intoreleasefrom
test17
Aug 12, 2024
Merged

chore: batching updates for a few widgets to reduce rerenders#35594
vsvamsi1 merged 1 commit intoreleasefrom
test17

Conversation

@vsvamsi1
Copy link
Contributor

@vsvamsi1 vsvamsi1 commented Aug 12, 2024

Description

Each meta update would cause rerender for the the widget, by batching meta updates we reduce the number of rerenders thereby improving the overall performance of the widget.

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/10346452761
Commit: c1abc97
Cypress dashboard.
Tags: @tag.All
Spec:


Mon, 12 Aug 2024 06:26:33 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced batch processing for widget metadata updates across various widgets, improving state management efficiency.
    • Introduced new methods for committing batch updates, streamlining interaction handling.
  • Bug Fixes

    • Improved performance and consistency in widget state updates, reducing unnecessary re-renders.
  • Refactor

    • Modified existing update methods to utilize batching for more organized state management.
  • Tests

    • Adjustments made to ensure tests align with the new batch update functionality.

@vsvamsi1 vsvamsi1 self-assigned this Aug 12, 2024
@vsvamsi1 vsvamsi1 changed the title batching updates for a few widgets to reduce rerenders chore: batching updates for a few widgets to reduce rerenders Aug 12, 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 Aug 12, 2024
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 12, 2024

Walkthrough

The recent changes across various widget components focus on optimizing metadata updates by transitioning to a batching mechanism. This approach replaces direct state updates with methods like pushBatchMetaUpdates and commitBatchMetaUpdates, enhancing performance and state management efficiency. The modifications streamline the control flow, reduce re-renders, and improve the overall responsiveness of the widgets, marking a significant improvement in how user interactions are handled.

Changes

Files Change Summary
app/client/src/widgets/SelectWidget/... Refactored metadata updates to use batching via pushBatchMetaUpdates and commitBatchMetaUpdates.
app/client/src/widgets/wds/WDSCheckboxGroupWidget/... Updated onChange to use batching for isDirty and selectedValues, reducing direct updates.
app/client/src/widgets/wds/WDSCheckboxWidget/... Enhanced onChange to employ pushBatchMetaUpdates for isDirty and isChecked, improving efficiency.
app/client/src/widgets/wds/WDSInputWidget/... Replaced direct state updates with batching for parsedText, isDirty, and rawText in multiple methods.
app/client/src/widgets/wds/WDSRadioGroupWidget/... Utilized batching for isDirty and selectedOptionValue, consolidating updates for performance.
app/client/src/widgets/wds/WDSSwitchGroupWidget/... Employed batching in onChange for isDirty and selectedValues, enhancing state update efficiency.
app/client/src/widgets/wds/WDSSwitchWidget/... Modified onChange to batch updates for isDirty and isSwitchedOn, improving control flow.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Widget
    participant StateManager
    
    User->>Widget: Trigger Change
    Widget->>StateManager: pushBatchMetaUpdates(isDirty, newValue)
    Widget->>StateManager: pushBatchMetaUpdates(selectedValues)
    Widget->>StateManager: commitBatchMetaUpdates()
    StateManager-->>Widget: Update State
    Widget-->>User: Reflect Changes
Loading

🌟 In the land of code where the widgets play,
A batching magic leads the way!
With pushBatchMeta and commit in tow,
Performance shines, watch the updates glow!
No more delays, just smooth and quick,
Our little widgets dance with a flick! ✨


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.

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 8cbb13e and c1abc97.

Files selected for processing (7)
  • app/client/src/widgets/SelectWidget/widget/index.tsx (2 hunks)
  • app/client/src/widgets/wds/WDSCheckboxGroupWidget/widget/index.tsx (1 hunks)
  • app/client/src/widgets/wds/WDSCheckboxWidget/widget/index.tsx (1 hunks)
  • app/client/src/widgets/wds/WDSInputWidget/widget/index.tsx (3 hunks)
  • app/client/src/widgets/wds/WDSRadioGroupWidget/widget/index.tsx (1 hunks)
  • app/client/src/widgets/wds/WDSSwitchGroupWidget/widget/index.tsx (1 hunks)
  • app/client/src/widgets/wds/WDSSwitchWidget/widget/index.tsx (1 hunks)
Additional comments not posted (15)
app/client/src/widgets/wds/WDSSwitchWidget/widget/index.tsx (1)

83-95: Great use of batching for meta updates!

The transition from direct updates to using pushBatchMetaUpdates and commitBatchMetaUpdates is a smart move. It reduces the number of rerenders by batching updates, which can significantly enhance performance. Ensure that these changes are thoroughly tested to confirm they behave as expected in all scenarios.

app/client/src/widgets/wds/WDSCheckboxWidget/widget/index.tsx (1)

84-96: Efficient state management with batching!

The use of pushBatchMetaUpdates and commitBatchMetaUpdates in the onChange method is a commendable approach to optimize state management. This should help in reducing unnecessary rerenders and improving performance. Be sure to validate these changes with comprehensive tests to ensure they handle all edge cases correctly.

app/client/src/widgets/wds/WDSSwitchGroupWidget/widget/index.tsx (1)

90-102: Batching updates for better performance!

The implementation of pushBatchMetaUpdates and commitBatchMetaUpdates in the onChange method is a well-considered enhancement. It consolidates state updates, reducing rerenders and potentially improving performance. Ensure these changes are thoroughly tested to verify their effectiveness and correctness in all use cases.

app/client/src/widgets/wds/WDSCheckboxGroupWidget/widget/index.tsx (2)

99-101: Efficient State Management with Batching.

The introduction of pushBatchMetaUpdates for handling the isDirty state is a great way to optimize performance by reducing unnecessary rerenders. Ensure that this batching mechanism is consistently used throughout the widget to maintain efficiency.


104-111: Batching Updates for Selected Values.

Using pushBatchMetaUpdates for selectedValues along with event handling is a smart move to streamline updates and improve performance. This approach minimizes the number of state changes that trigger rerenders. Make sure all event-related logic is correctly handled.

app/client/src/widgets/wds/WDSRadioGroupWidget/widget/index.tsx (2)

112-115: Improved Efficiency with Batching.

The use of pushBatchMetaUpdates to set isDirty is a good practice for optimizing widget performance. This change helps in reducing unnecessary rerenders by batching state updates. Ensure this pattern is applied consistently across similar components.


118-125: Streamlined State Updates for Selection Changes.

Implementing pushBatchMetaUpdates for selectedOptionValue with event handling is an effective way to enhance performance. This approach ensures that updates are efficiently batched, reducing the frequency of state changes. Verify that all associated event logic is correctly managed.

app/client/src/widgets/wds/WDSInputWidget/widget/index.tsx (4)

155-160: Optimized Component Updates with Batching.

Using pushBatchMetaUpdates in componentDidUpdate for parsedText is a smart way to consolidate updates and improve performance. This reduces unnecessary rerenders by batching state changes. Ensure the logic for parsing text is accurate.


Line range hint 167-179: Batching Logic for Efficient State Management.

The use of pushBatchMetaUpdates for resetting isDirty is a good approach to manage state changes efficiently. This helps in maintaining optimal performance by minimizing rerenders. Ensure that all conditions for updating isDirty are correctly handled.


Line range hint 183-201: Efficient Handling of Value Changes.

The onValueChange method effectively uses pushBatchMetaUpdates for parsedText and rawText, which is beneficial for performance. This batching mechanism ensures that state updates are efficiently managed. Verify that the parsing logic is consistent with expected behavior.


205-208: Streamlined Reset Logic with Batching.

The resetWidgetText method's use of pushBatchMetaUpdates for resetting text values is a great way to optimize performance. This approach ensures that updates are batched, reducing the frequency of rerenders. Confirm that the reset logic aligns with the intended functionality.

app/client/src/widgets/SelectWidget/widget/index.tsx (4)

Line range hint 896-917:
Great use of batching for performance improvement!

The introduction of pushBatchMetaUpdates and commitBatchMetaUpdates effectively minimizes rerenders by batching updates. This change improves performance by reducing the number of state updates and rerenders. Ensure that all necessary updates are included in the batch and that commitBatchMetaUpdates is invoked at the right time to apply all changes.


917-917: Ensure commitBatchMetaUpdates is called appropriately.

Calling commitBatchMetaUpdates here ensures that all queued updates are applied at once. This is crucial for maintaining consistency and minimizing unnecessary renders.


896-899: Verify the logic for updating isDirty.

The logic correctly identifies when the isDirty property should be updated based on changes to the selected option value. This ensures that the widget accurately reflects its state.


Line range hint 902-915:
Confirm correctness of batched updates for label and value.

The updates to label and value are correctly batched using pushBatchMetaUpdates. This ensures that changes are efficiently managed and applied together, reducing unnecessary renders.

@vsvamsi1 vsvamsi1 added the ok-to-test Required label for CI label Aug 12, 2024
@vsvamsi1 vsvamsi1 requested review from KelvinOm and dvj1988 August 12, 2024 06:53
@vsvamsi1 vsvamsi1 merged commit b8df54c into release Aug 12, 2024
@vsvamsi1 vsvamsi1 deleted the test17 branch August 12, 2024 08:24
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