⚡ Bolt: Optimize VaultSidebar tree building and search complexity#52
⚡ Bolt: Optimize VaultSidebar tree building and search complexity#52AashishH15 wants to merge 1 commit into
Conversation
|
👋 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. |
There was a problem hiding this comment.
Code Review
This pull request optimizes the performance of the vault sidebar by splitting a large useMemo block into two separate blocks, isolating static tree building from dynamic search filtering to prevent rebuilding the tree on every keystroke. It also replaces an O(N) array search with an O(1) hash map lookup. The review feedback points out that the lookup of subVault to find parentVaultId is redundant because the parent vault ID is already added unconditionally, and suggests simplifying this block and removing vaultById from the dependency array.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if (node.subVaultId) { | ||
| matchSubVaults.add(node.subVaultId); | ||
| // Also find the root vault for this sub-vault | ||
| const subVault = vaults.find((v) => v.id === node.subVaultId); | ||
| const subVault = vaultById[node.subVaultId]; | ||
| if (subVault?.parentVaultId) { | ||
| matchVaults.add(subVault.parentVaultId); | ||
| } |
There was a problem hiding this comment.
The lookup of subVault from vaultById to find parentVaultId is redundant.
In a two-level vault hierarchy, node.vaultId is already the top-level (parent) vault ID. Therefore, subVault.parentVaultId is always equal to node.vaultId. Since matchVaults.add(node.vaultId) is already called unconditionally on line 738, we can completely eliminate this lookup and simplify the block.
if (node.subVaultId) {
matchSubVaults.add(node.subVaultId);
}
| resultCount: count, | ||
| }; | ||
| }, [allNodes, normalizedQuery, vaults]); | ||
| }, [allNodes, normalizedQuery, vaults, vaultById]); |
There was a problem hiding this comment.
Since vaultById is no longer used in this useMemo block after removing the redundant lookup, we can remove it from the dependency array. This prevents unnecessary dependency tracking and potential re-runs.
| }, [allNodes, normalizedQuery, vaults, vaultById]); | |
| }, [allNodes, normalizedQuery, vaults]); |
💡 What: Split a dual-responsibility
useMemoblock inVaultSidebar.tsxto separate tree-shaping from search-filtering. Also replaced anarray.find()search loop lookup with an O(1) hash map lookup.🎯 Why: Previously, the tree grouping and sorting was unnecessarily recomputed on every search keystroke, and the nested
.find()scan created an O(N * V) complexity bottleneck during search processing.📊 Impact: Eliminates O(N * V) search overhead and prevents deep tree recomputation on simple keystrokes, significantly improving rendering fluidity on large vaults.
🔬 Measurement: Noticeably smoother search-bar typing performance when a vault contains a large number of nested nodes.
PR created automatically by Jules for task 7507436373541710408 started by @AashishH15