Skip to content

Bolt: optimize input mapping lookup time complexity#3943

Open
georgi wants to merge 1 commit into
mainfrom
bolt-input-mapping-selector-16949777695451353028
Open

Bolt: optimize input mapping lookup time complexity#3943
georgi wants to merge 1 commit into
mainfrom
bolt-input-mapping-selector-16949777695451353028

Conversation

@georgi

@georgi georgi commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

What

Refactored InputMappingSelector.tsx to precompute a Map of previousNodes using useMemo for O(1) lookups inside the properties.map loop.

Why

Previously, inside the properties.map() iteration (size N), an O(M) previousNodes.find(...) lookup was performed. This resulted in an $O(M \times N)$ time complexity. This inefficiency scales poorly and causes unnecessary UI thread overhead when dealing with numerous properties or long chains.

Impact

Time complexity is reduced from $O(M \times N)$ to $O(N + M)$. The previousNodes are looped over exactly once in useMemo to build the Map, allowing O(1) lookups for each property mapping.

Verification

  • Applied the code patch successfully.
  • Ran tests natively (cd web && npm run test) and all tests passed (no regressions).
  • Ran linter natively (cd web && npx oxlint src) and there were 0 new warnings/errors.

PR created automatically by Jules for task 16949777695451353028 started by @georgi

Optimize an O(M * N) algorithmic inefficiency where an array .find() method was being called inside a .map() iteration over node properties. Precomputing a Map of previous nodes inside a useMemo hook reduces the time complexity to O(M + N).

Co-authored-by: georgi <19498+georgi@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@georgi georgi left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The optimization itself is correct — precomputing the previousNodesMap via useMemo for O(1) lookups is a good improvement.

However, this PR ships a .orig backup file that should not be committed:

  • web/src/components/chain_editor/InputMappingSelector.tsx.orig — this is a 288-line copy of the original file, likely left by a merge tool or editor. Please remove it before merging.

Generated by Claude Code

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.

1 participant