⚡ Optimize handleSaveAll file tree search using Map lookups - #6
⚡ Optimize handleSaveAll file tree search using Map lookups#6beingniloy wants to merge 3 commits into
Conversation
Replaces the O(N * M) recursive lookup inside the save-all loop with an O(N + M) map-based lookup. The file tree is traversed once before the loop to construct a flat Map of file paths to items, allowing O(1) lookups during iteration. Co-authored-by: beingniloy <235952944+beingniloy@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. |
Replaces the O(N * M) recursive lookup inside the save-all loop with an O(N + M) map-based lookup. The file tree is traversed once before the loop to construct a flat Map of file paths to items, allowing O(1) lookups during iteration. Co-authored-by: beingniloy <235952944+beingniloy@users.noreply.github.com>
Replaces the O(N * M) recursive lookup inside the save-all loop with an O(N + M) map-based lookup. The file tree is traversed once before the loop to construct a flat Map of file paths to items, allowing O(1) lookups during iteration. Co-authored-by: beingniloy <235952944+beingniloy@users.noreply.github.com>
This PR optimizes the file tree lookups within
handleSaveAllinsideFileSystemContext.tsx.💡 What
We refactored$O(1)$ key lookup on the $O(N)$ time per tab).
handleSaveAllto traverse thefilestree once and construct a temporary flatMapmapping file paths toFileSystemItemnodes. When iterating through the list ofopenTabsto find the corresponding file contents for dirty files, we perform anMaprather than calling the recursivefindFileInTreehelper (which runs in🎯 Why
Previously, if a user had$M$ open dirty tabs in a workspace containing $N$ files, saving all tabs resulted in an $O(N \times M)$ operation because
findFileInTreerecursively scans the tree structure from scratch for each tab. Under large file trees and multiple open tabs, this causes significant lag and UI thread blocking.📊 Measured Improvement
Using a benchmark simulating a deep file tree structure with 7,776 files and 1,000 open tabs:
No functional regressions or compilation warnings are introduced.
PR created automatically by Jules for task 18387409122599181350 started by @beingniloy