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

Query performance operators #4875

Merged
merged 3 commits into from
Oct 4, 2024
Merged

Conversation

benjaminpkane
Copy link
Contributor

@benjaminpkane benjaminpkane commented Oct 1, 2024

What changes are proposed in this pull request?

Adds enable_query_performance and disable_query_performance operators

Screen.Recording.2024-10-01.at.4.14.58.PM.mov

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

todo

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

    • Introduced new operators to enable and disable query performance.
    • Added a custom hook for managing query performance thresholds.
    • Enhanced execution context to include query performance metrics.
  • Bug Fixes

    • Improved validation logic for operator prompts to ensure accurate input handling.
  • Documentation

    • Updated exports to include the new useQueryPerformance hook.
  • Refactor

    • Enhanced context management for operator execution and performance tracking.

@benjaminpkane benjaminpkane added the app Issues related to App features label Oct 1, 2024
@benjaminpkane benjaminpkane self-assigned this Oct 1, 2024
Copy link
Contributor

coderabbitai bot commented Oct 1, 2024

Walkthrough

The changes introduce new classes for managing query performance within an operator framework, specifically DisableQueryPerformance and EnableQueryPerformance, which extend the existing Operator class. Additionally, the RawContext type and ExecutionContext class are updated to include a new optional property for tracking query performance. The modifications also enhance various functions related to operator execution and context management, including the addition of a custom hook for managing performance thresholds. Overall, the updates integrate new functionalities while maintaining the existing structure.

Changes

File Path Change Summary
app/packages/operators/src/built-in-operators.ts - Added classes: DisableQueryPerformance and EnableQueryPerformance, both extending Operator.
- Updated registerBuiltInOperators to include new operators.
app/packages/operators/src/operators.ts - Updated RawContext to include optional queryPerformance property.
- Added getter for queryPerformance in ExecutionContext.
- Modified executeOperatorWithContext to include queryPerformance in payload.
app/packages/operators/src/state.ts - Enhanced globalContextSelector to include queryPerformance.
- Updated useExecutionContext to pass queryPerformance to ExecutionContext.
app/packages/state/src/hooks/index.ts - Added export for useQueryPerformance hook from ./useQueryPerformance.
app/packages/state/src/hooks/useQueryPerformance.ts - Introduced useQueryPerformance hook for managing performance thresholds with Recoil state.
fiftyone/operators/executor.py - Added query_performance property to ExecutionContext class to check if query performance is enabled.

Possibly related PRs

  • better group slice support for operators #4850: The changes in this PR enhance the functionality of the defineCustomPanel function, which may relate to the new operator classes that also involve context management and performance tracking.

Suggested reviewers

  • ritch
  • brimoor

Poem

🐇 In the burrow where changes bloom,
New operators rise, dispelling gloom.
Performance tracked with a gentle hop,
Enabling features that never stop.
With every query, our paths align,
In the world of code, we brightly shine! ✨


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.

@benjaminpkane benjaminpkane marked this pull request as ready for review October 4, 2024 14:58
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 (6)
app/packages/state/src/hooks/useQueryPerformance.ts (2)

1-9: Consider naming the exported function for better maintainability

While exporting a default function is valid, naming it (e.g., useQueryPerformance) would improve code readability and make it easier to debug or reference in other parts of the codebase.

Consider updating the export as follows:

-export default function () {
+export default function useQueryPerformance() {

18-32: LGTM: The enable function is well-implemented with a minor suggestion

The enable function is correctly implemented using useRecoilCallback. It handles the optional threshold parameter well and has a good fallback mechanism. The asynchronous operations are properly managed.

Consider adding a type annotation for the threshold parameter to improve type safety:

-      async (threshold?: number) => {
+      async (threshold?: number | null) => {

This change allows for explicitly setting the threshold to null if needed, matching the behavior of the disable function.

app/packages/operators/src/operators.ts (2)

94-94: LGTM! Consider adding documentation.

The addition of the queryPerformance property to the RawContext type is appropriate. It's correctly defined as an optional boolean, which aligns well with its purpose as a performance tracking flag.

Consider adding a brief comment explaining the purpose of this property and when it should be set.


140-142: LGTM! Consider a minor optimization.

The queryPerformance getter is well-implemented, following the pattern of other getters in the class and ensuring type consistency by using Boolean().

For a slight optimization, you could use the logical OR operator instead of Boolean():

- return Boolean(this._currentContext.queryPerformance);
+ return this._currentContext.queryPerformance || false;

This achieves the same result but avoids the function call to Boolean().

app/packages/operators/src/built-in-operators.ts (2)

1316-1332: LGTM! Consider adding a resolveInput method for consistency.

The DisableQueryPerformance class is well-implemented and follows the structure of other operator classes. It correctly extends the Operator class, sets the _builtIn property, and implements the required methods.

For consistency with other operator classes, consider adding a resolveInput method, even if it returns an empty object:

async resolveInput(): Promise<types.Property> {
  return new types.Property(new types.Object());
}

This addition would make the class structure more uniform with other operators in the file.


1334-1350: LGTM! Consider adding a resolveInput method for consistency.

The EnableQueryPerformance class is well-implemented and follows the structure of other operator classes. It correctly extends the Operator class, sets the _builtIn property, and implements the required methods.

As with the DisableQueryPerformance class, consider adding a resolveInput method for consistency:

async resolveInput(): Promise<types.Property> {
  return new types.Property(new types.Object());
}

This addition would make the class structure more uniform with other operators in the file.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 77f664c and 722db42.

📒 Files selected for processing (6)
  • app/packages/operators/src/built-in-operators.ts (2 hunks)
  • app/packages/operators/src/operators.ts (4 hunks)
  • app/packages/operators/src/state.ts (5 hunks)
  • app/packages/state/src/hooks/index.ts (1 hunks)
  • app/packages/state/src/hooks/useQueryPerformance.ts (1 hunks)
  • fiftyone/operators/executor.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
app/packages/operators/src/built-in-operators.ts (1)

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

app/packages/operators/src/operators.ts (1)

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

app/packages/operators/src/state.ts (1)

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

app/packages/state/src/hooks/index.ts (1)

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

app/packages/state/src/hooks/useQueryPerformance.ts (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 (10)
app/packages/state/src/hooks/useQueryPerformance.ts (3)

10-16: LGTM: The disable function is well-implemented

The disable function correctly uses useRecoilCallback to set the lightningThreshold state to null. The empty dependency array ensures optimal performance by creating the callback only once.


34-41: LGTM: Effective use of useMemo for performance optimization

The hook's return value is correctly memoized using useMemo. This optimization prevents unnecessary re-renders by ensuring the returned object is only recreated when either the disable or enable function changes. The dependency array is correctly specified.


1-41: Overall: Well-implemented custom hook for query performance management

The useQueryPerformance hook is thoughtfully designed and implemented. It effectively leverages Recoil for state management and follows React best practices. The hook provides clear and concise functions for enabling and disabling the query performance threshold, with good fallback mechanisms and performance optimizations.

Great job on creating a reusable and efficient solution for managing query performance in the application!

app/packages/state/src/hooks/index.ts (1)

27-27: LGTM: New hook export aligns with PR objectives

The addition of the useQueryPerformance hook export is consistent with the existing code structure and follows the established pattern in this file. This change directly supports the PR's objective of introducing query performance operators.

app/packages/operators/src/operators.ts (1)

714-714: LGTM! Verify server-side handling.

The addition of query_performance to the payload is correct and consistent with the existing code structure.

Ensure that the server-side code is updated to handle this new property. Run the following script to check for server-side changes:

app/packages/operators/src/built-in-operators.ts (2)

1401-1402: LGTM! New operators correctly registered.

The DisableQueryPerformance and EnableQueryPerformance operators are correctly registered in the registerBuiltInOperators function. These additions are consistent with the registration of other operators in the function.


Line range hint 1316-1402: Summary: New query performance operators successfully implemented

The changes introduce two new operator classes, DisableQueryPerformance and EnableQueryPerformance, which extend the functionality of the application to control query performance. These classes are well-implemented, following the existing patterns in the codebase, and are correctly registered in the registerBuiltInOperators function.

The new operators will allow users to enable or disable query performance features, potentially improving the flexibility and control over the application's behavior.

Consider adding resolveInput methods to both new classes for complete consistency with other operators, but this is a minor suggestion and doesn't affect the functionality of the implementation.

Overall, these changes are well-structured and integrate seamlessly with the existing codebase.

fiftyone/operators/executor.py (1)

716-720: LGTM: New property added for query performance.

The new query_performance property has been added to the ExecutionContext class. This property allows checking whether query performance is enabled for the current execution context.

A few observations:

  1. The property is implemented as a getter method, which is appropriate for this use case.
  2. It correctly retrieves the value from the request_params dictionary, defaulting to None if the key is not present.
  3. The property is well-documented with a clear and concise docstring.

This addition enhances the functionality of the ExecutionContext class by providing a way to access query performance settings, which aligns with the PR objectives of introducing query performance operators.

app/packages/operators/src/state.ts (2)

Line range hint 97-109: Verify that queryPerformance is correctly typed and integrated.

The queryPerformance variable is derived from checking if fos.lightningThreshold is a number and is added to the global context. Ensure that all relevant TypeScript interfaces or types include queryPerformance to maintain type safety across the application.


Line range hint 150-184: Ensure queryPerformance is properly handled in ExecutionContext.

In the useExecutionContext function, queryPerformance is destructured from curCtx, passed into ExecutionContext, and included in the dependency array. Verify that the ExecutionContext class and any related type definitions are updated to accept and correctly utilize queryPerformance.

Copy link
Contributor

@minhtuev minhtuev left a comment

Choose a reason for hiding this comment

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

Functionality works 🚀 🙇‍♂️

@benjaminpkane benjaminpkane merged commit 69a89e8 into develop Oct 4, 2024
13 checks passed
@benjaminpkane benjaminpkane deleted the enable-query-performance branch October 4, 2024 21:23
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