Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/server/src/utils/buildAgentflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,9 +830,9 @@ async function determineNodesToIgnore(

// Find nodes to ignore based on unfulfilled conditions
for (const index of unfulfilledIndexes) {
const ignoreEdge = edges.find((edge) => edge.source === nodeId && edge.sourceHandle === `${nodeId}-output-${index}`)
const ignoreEdges = edges.filter((edge) => edge.source === nodeId && edge.sourceHandle === `${nodeId}-output-${index}`)

if (ignoreEdge) {
for (const ignoreEdge of ignoreEdges) {
ignoreNodeIds.push(ignoreEdge.target)
}
}
Comment on lines 832 to 838

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.

medium

Improvement Opportunity

Currently, edges.filter is called inside a loop over unfulfilledIndexes. This results in $O(N \times M)$ complexity, where $N$ is the number of edges and $M$ is the number of unfulfilled indexes.

We can optimize this to $O(N + M)$ by pre-computing the unfulfilled source handles in a Set and filtering the edges array in a single pass.

        const unfulfilledSourceHandles = new Set(unfulfilledIndexes.map((index) => nodeId + "-output-" + index))
        const ignoreEdges = edges.filter((edge) => edge.source === nodeId && unfulfilledSourceHandles.has(edge.sourceHandle))

        for (const ignoreEdge of ignoreEdges) {
            ignoreNodeIds.push(ignoreEdge.target)
        }

Expand Down