Skip to content

⚡ Bolt: Optimize VaultSidebar tree building and search complexity#52

Draft
AashishH15 wants to merge 1 commit into
mainfrom
bolt-vaultsidebar-optimize-7507436373541710408
Draft

⚡ Bolt: Optimize VaultSidebar tree building and search complexity#52
AashishH15 wants to merge 1 commit into
mainfrom
bolt-vaultsidebar-optimize-7507436373541710408

Conversation

@AashishH15

Copy link
Copy Markdown
Member

💡 What: Split a dual-responsibility useMemo block in VaultSidebar.tsx to separate tree-shaping from search-filtering. Also replaced an array.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

@google-labs-jules

Copy link
Copy Markdown

👋 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.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

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.

Comment on lines 730 to 736
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);
}

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

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]);

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

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.

Suggested change
}, [allNodes, normalizedQuery, vaults, vaultById]);
}, [allNodes, normalizedQuery, vaults]);

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