Bolt: optimize input mapping lookup time complexity#3943
Conversation
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>
|
👋 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 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
left a comment
There was a problem hiding this comment.
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
What
Refactored
InputMappingSelector.tsxto precompute aMapofpreviousNodesusinguseMemofor O(1) lookups inside theproperties.maploop.Why
Previously, inside the$O(M \times N)$ time complexity. This inefficiency scales poorly and causes unnecessary UI thread overhead when dealing with numerous properties or long chains.
properties.map()iteration (size N), an O(M)previousNodes.find(...)lookup was performed. This resulted in anImpact
Time complexity is reduced from$O(M \times N)$ to $O(N + M)$ . The
previousNodesare looped over exactly once inuseMemoto build the Map, allowing O(1) lookups for each property mapping.Verification
cd web && npm run test) and all tests passed (no regressions).cd web && npx oxlint src) and there were 0 new warnings/errors.PR created automatically by Jules for task 16949777695451353028 started by @georgi