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

perf improvement: remove handler from onlookersetsubscribers as tooltip changes #5019

Merged
merged 2 commits into from
Oct 31, 2024

Conversation

sashankaryal
Copy link
Contributor

@sashankaryal sashankaryal commented Oct 31, 2024

What changes are proposed in this pull request?

Before this, we were not cleaning up on-looker-set subscribers.

How is this patch tested? If it is not, please explain why.

Locally.

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features
    • Enhanced performance of the ModalSample component through improved event handling and memoization.
  • Bug Fixes
    • Refined cleanup process for event listeners to ensure proper removal during component updates and unmounting.

@sashankaryal sashankaryal self-assigned this Oct 31, 2024
Copy link
Contributor

coderabbitai bot commented Oct 31, 2024

Walkthrough

The changes in this pull request focus on the ModalSample component within ModalSamplePlugin.tsx. The modifications include the addition of useCallback and useMemo for performance optimization, the introduction of a new addTooltipEventListener function, and a refactor of the useEffect hook to utilize this memoized function for event listener management. The cleanup process in the useEffect has also been updated to ensure proper function removal during component updates or unmounting.

Changes

File Path Change Summary
app/packages/core/src/components/Modal/ModalSamplePlugin.tsx Updated import statement to include useCallback and useMemo. Refactored useEffect to use addTooltipEventListener, ensuring memoization and proper cleanup.

Poem

In the modal's cozy den,
A tooltip's dance begins again.
With hooks that twist and turn with grace,
Performance shines in this lively space.
So hop along, let events play,
In the rabbit's world, we optimize the day! 🐇✨


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 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.

@sashankaryal sashankaryal added the app Issues related to App features label Oct 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

🧹 Outside diff range and nitpick comments (1)
app/packages/core/src/components/Modal/ModalSamplePlugin.tsx (1)

3-3: Remove unused import useCallback.

The useCallback hook is imported but not utilized in the component. Consider removing it to maintain clean imports.

-import React, { Suspense, useCallback, useEffect, useMemo } from "react";
+import React, { Suspense, useEffect, useMemo } from "react";
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5eac141 and 34fb6ee.

📒 Files selected for processing (1)
  • app/packages/core/src/components/Modal/ModalSamplePlugin.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/core/src/components/Modal/ModalSamplePlugin.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (2)
app/packages/core/src/components/Modal/ModalSamplePlugin.tsx (2)

57-74: Well-implemented cleanup logic!

The useEffect implementation properly manages both the subscription and cleanup of tooltip event listeners. The dependency array is complete, and the cleanup function ensures that both the event listener and subscriber are removed correctly.


57-74: Verify memory cleanup with multiple modal operations.

While the implementation looks correct, it's important to verify that memory is properly cleaned up after multiple modal open/close operations.

✅ Verification successful

Memory cleanup implementation is correctly handled

The implementation properly manages cleanup through multiple mechanisms:

  • The onLookerSetSubscribers array is maintained in the Modal component and shared via context
  • Event listeners are properly added and removed in the cleanup function
  • The subscriber list is correctly filtered during cleanup to remove the specific listener
  • The cleanup pattern is consistent across the codebase with no conflicting implementations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other uses of onLookerSetSubscribers to ensure consistent cleanup
rg -A 5 "onLookerSetSubscribers" --type ts --type tsx

Length of output: 81


Script:

#!/bin/bash
# Search for onLookerSetSubscribers with correct file type patterns
rg -A 5 "onLookerSetSubscribers" -g "*.tsx" -g "*.ts"

# Search for any tooltip-related event listeners to verify cleanup patterns
rg -A 5 "tooltip.*EventListener" -g "*.tsx" -g "*.ts"

# Search for Modal component usage patterns
rg -A 5 "ModalSamplePlugin" -g "*.tsx" -g "*.ts"

Length of output: 7621

Copy link
Contributor

@benjaminpkane benjaminpkane left a comment

Choose a reason for hiding this comment

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

LGTM. Much smoother now! 🧈

@benjaminpkane benjaminpkane merged commit 35f8f61 into release/v1.0.2 Oct 31, 2024
11 checks passed
@benjaminpkane benjaminpkane deleted the fix/release-event-listener-adder branch October 31, 2024 16:20
@coderabbitai coderabbitai bot mentioned this pull request Nov 2, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app Issues related to App features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants