Skip to content

Performance: Decouple state.flow.nodes into state.flow.nodes and state.flow.nodeConfigs#68

Merged
srijanpatel merged 74 commits intomainfrom
perf/flowSlicev2
Jan 1, 2025
Merged

Performance: Decouple state.flow.nodes into state.flow.nodes and state.flow.nodeConfigs#68
srijanpatel merged 74 commits intomainfrom
perf/flowSlicev2

Conversation

@JeanKaddour
Copy link
Copy Markdown
Contributor

@JeanKaddour JeanKaddour commented Dec 29, 2024

This pull request focuses on refactoring the flow management components in the frontend, particularly by decoupling the updateNodeData function into updateNodeDataOnly and updateNodeConfigOnly to optimize component re-renders. Additionally, there are several improvements, eg., using React.memo.

Refactoring and Optimization:


Important

Refactor frontend flow management by decoupling node data and configuration updates, optimizing re-renders, and improving performance.

  • Behavior:
    • Decouples updateNodeData into updateNodeDataOnly and updateNodeConfigOnly in flowSlice.ts to separate node data and configuration updates.
    • Introduces nodeConfigs in flowSlice.ts to store node configurations separately from node data.
    • Updates components like Header.tsx, BaseNode.tsx, and DynamicNode.tsx to use updateNodeDataOnly and updateNodeConfigOnly.
  • Components:
    • Applies React.memo to BaseNode.tsx and DynamicNode.tsx with custom comparators to optimize re-renders.
    • Refactors DeployModal.tsx and RunModal.tsx to use nodeConfigs for input variables.
    • Updates NodeSidebar.tsx to handle node configuration changes and title updates.
  • Utilities:
    • Adds createNode function in nodeFactory.ts to generate nodes with separate configurations.
    • Updates flowUtils.tsx to support new node creation and connection logic.
  • Misc:
    • Fixes various minor issues and optimizes code across multiple files.

This description was created by Ellipsis for c39e4ee. It will automatically update as commits are pushed.

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on fc545ef in 58 seconds

More details
  • Looked at 459 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. frontend/src/components/canvas/RunViewFlowCanvas.tsx:218
  • Draft comment:
    Excessive use of key attributes on non-list elements can lead to unnecessary re-renders. Consider removing key attributes from elements that do not require them, such as single instances of components like Background, Operator, and NodeSidebar. This comment applies to similar instances in this file and others.
  • Reason this comment was not posted:
    Comment was on unchanged code.
2. frontend/src/components/nodes/BaseNode.tsx:334
  • Draft comment:
    Excessive use of key attributes on non-list elements can lead to unnecessary re-renders. Consider removing key attributes from elements that do not require them, such as single instances of components like Alert, Handle, Card, and Button. This comment applies to similar instances in this file and others.
  • Reason this comment was not posted:
    Marked as duplicate.
3. frontend/src/components/nodes/DynamicNode.tsx:130
  • Draft comment:
    Excessive use of key attributes on non-list elements can lead to unnecessary re-renders. Consider removing key attributes from elements that do not require them, such as single instances of components like Input and NodeOutputDisplay. This comment applies to similar instances in this file and others.
  • Reason this comment was not posted:
    Marked as duplicate.
4. frontend/src/components/nodes/nodeSidebar/NodeSidebar.tsx:247
  • Draft comment:
    Excessive use of key attributes on non-list elements can lead to unnecessary re-renders. Consider removing key attributes from elements that do not require them, such as single instances of components like Select, Input, and TextEditor. This comment applies to similar instances in this file and others.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_v98NVtagFZov1lxE


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Incremental review on 63bc8a4 in 46 seconds

More details
  • Looked at 112 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_ltyz5bpJOOCVh4SF


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Comment thread frontend/src/utils/flowUtils.tsx Outdated
}
};

export const getWorkflowInputVariables = (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The function getWorkflowInputVariables should return an object, not an array, as it is used to access keys in the DeployModal and RunModal components.

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 5a23fbb in 55 seconds

More details
  • Looked at 69 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. frontend/src/components/modals/RunModal.tsx:23
  • Draft comment:
    The getWorkflowInputVariables function is removed from imports but still used in the code. This will cause a reference error. Ensure to update the code to use the new logic for obtaining workflow input variables.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
2. frontend/src/components/modals/DeployModal.tsx:15
  • Draft comment:
    The getWorkflowInputVariables function is removed from imports but still used in the code. This will cause a reference error. Ensure to update the code to use the new logic for obtaining workflow input variables.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_3VzfW8gK31qQKg1e


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on b798799 in 41 seconds

More details
  • Looked at 16 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. frontend/src/components/modals/DeployModal.tsx:31
  • Draft comment:
    getApiEndpoint() should be called within the code example strings to ensure the latest endpoint is used. Consider using a function to generate the code examples dynamically.
  • Reason this comment was not posted:
    Comment was not on a valid diff hunk.

Workflow ID: wflow_cA0UwFhP9XFCzsac


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Incremental review on 0092249 in 50 seconds

More details
  • Looked at 26 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_MYT3mhQwI6ZerxWd


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

node = nodes.find(node => node.data?.config?.title === task.node_id);
// find the node by title in nodeConfigs
const state = store.getState();
const correspondingNodeId = Object.keys(state.flow.nodeConfigs).find(key => state.flow.nodeConfigs[key].title === nodeId);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider refactoring the logic for finding a node by title in nodeConfigs into a utility function to avoid code duplication and improve maintainability.

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Incremental review on 3cf89e4 in 42 seconds

More details
  • Looked at 12 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_R96cWnN00jC0Ks7T


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

// Update source handle if this is the source node
if (edge.source === nodeId && edge.sourceHandle === oldTitle) {
updatedEdge.sourceHandle = newTitle;
updatedEdge.targetHandle = newTitle;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The line updatedEdge.targetHandle = newTitle; is incorrectly placed inside the condition for updating the source handle. It should be in a separate condition for updating the target handle.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is the intended behaviour

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on f69c557 in 47 seconds

More details
  • Looked at 22 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. frontend/src/components/nodes/DynamicNode.tsx:75
  • Draft comment:
    The change from edge.source + '_' + edge.sourceHandle to edge.targetHandle might lead to loss of context or uniqueness in the title. Consider whether this change is intentional and if it maintains the necessary information.
  • Reason this comment was not posted:
    Comment did not seem useful.

Workflow ID: wflow_vFzHqsj29TWyAWkv


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on e71f972 in 24 seconds

More details
  • Looked at 13 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. frontend/src/components/nodes/InputNode.tsx:238
  • Draft comment:
    Ensure nodeConfig?.title is unique across nodes to prevent potential issues with the Handle component's id prop.
  • Reason this comment was not posted:
    Comment did not seem useful.

Workflow ID: wflow_7XUFxGHkOjjKRnPa


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 19f9fed in 43 seconds

More details
  • Looked at 14 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. frontend/src/components/Header.tsx:267
  • Draft comment:
    Using inputNode?.data?.title as an identifier may lead to unexpected behavior if title is not unique or intended for identification. Consider using inputNode?.id for a more reliable identifier.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The code actually has a fallback to id if title is not available. Looking at the broader context, this change seems intentional - there's code elsewhere (L127-131) that shows the codebase sometimes needs to look up nodes by title. The comment misses that id is already used as a fallback. The change appears to be making the code more robust, not less.
    I could be missing some edge cases where using title, even with an id fallback, could cause issues. There might be a good reason why using title at all is problematic.
    The code's fallback pattern and the existence of title-based lookups elsewhere in the file strongly suggest this is an intentional design choice that the team has already thought through.
    Delete this comment. The code already handles the concern by using id as a fallback, and the broader context shows that using title as an identifier is an intentional pattern in this codebase.

Workflow ID: wflow_4qKH7cHQIHlHH9vV


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on c39e4ee in 33 seconds

More details
  • Looked at 138 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 5 drafted comments based on config settings.
1. frontend/src/components/nodes/logic/CoalesceNode.tsx:55
  • Draft comment:
    Consider extracting the logic inside the useState initializer function to a separate function for better readability and maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The use of useState with a function initializer is a good practice for performance optimization. However, the logic inside the initializer function is complex and could be extracted to a separate function for better readability and maintainability.
2. frontend/src/components/nodes/logic/CoalesceNode.tsx:82
  • Draft comment:
    The logic for computing updatedPredecessors is duplicated from the useState initializer. Consider refactoring to avoid code duplication.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The use of useEffect to recompute predecessor nodes is correct, but the logic is duplicated from the useState initializer. This could be refactored to avoid code duplication.
3. frontend/src/components/nodes/logic/CoalesceNode.tsx:144
  • Draft comment:
    Consider extracting the logic inside the map function in useMemo to a separate function for better readability.
  • Reason this comment was not posted:
    Confidence changes required: 33%
    The useMemo hook is used correctly to memoize the inputVariables array. However, the logic inside the map function is complex and could be extracted to a separate function for better readability.
4. frontend/src/components/nodes/logic/CoalesceNode.tsx:223
  • Draft comment:
    Consider extracting the logic for computing nodeWidth to a separate function for better readability.
  • Reason this comment was not posted:
    Confidence changes required: 33%
    The useEffect for setting nodeWidth is well-structured, but the logic for computing widths is complex and could be extracted to a separate function for better readability.
5. frontend/src/components/nodes/logic/CoalesceNode.tsx:298
  • Draft comment:
    Ensure that handleId is unique for each node to avoid potential issues with React's key prop.
  • Reason this comment was not posted:
    Confidence changes required: 33%
    The key prop for the input handle divs is constructed using both node.id and handleId, which is a good practice to ensure unique keys. However, ensure that handleId is always unique for each node to avoid potential issues.

Workflow ID: wflow_z6apHbWtLnnf6cSj


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@srijanpatel srijanpatel merged commit 0709846 into main Jan 1, 2025
@srijanpatel srijanpatel deleted the perf/flowSlicev2 branch January 7, 2025 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants