Skip to content

⚡ Bolt: [O(N) to O(1) FileList lookup]#19

Open
TheerasakPing wants to merge 2 commits intomainfrom
bolt/optimize-filelist-lookup-2359221673569039556
Open

⚡ Bolt: [O(N) to O(1) FileList lookup]#19
TheerasakPing wants to merge 2 commits intomainfrom
bolt/optimize-filelist-lookup-2359221673569039556

Conversation

@TheerasakPing
Copy link
Copy Markdown
Owner

💡 What: Replaced O(N) array scans (Array.some()) inside the sortedItems.map rendering loop in FileList.jsx with O(1) Set lookups. The Set objects for selected paths and cut clipboard items are computed using useMemo.

🎯 Why: Rendering FileList had a classic $O(N \cdot M)$ performance bottleneck. For every item $N$ in the directory, it iterated through the entire selectedItems array ($M$) and clipboard.items array to check if the item was selected or cut. This caused severe rendering lag for large directories with many selected items.

📊 Impact: Reduces rendering complexity of FileList from $O(N \cdot M)$ to $O(N + M)$. Lookup time per item during render drops from $O(M)$ to $O(1)$. This drastically reduces re-render times for folders with thousands of files, especially when performing multi-selection.

🔬 Measurement: Profile the React component tree while opening a directory with >1000 items and selecting all (Ctrl+A / Cmd+A). The render duration for FileList will be significantly reduced compared to the baseline.

Also updated the Bolt performance journal (.jules/bolt.md) with this critical learning regarding O(N*M) rendering anti-patterns.


PR created automatically by Jules for task 2359221673569039556 started by @TheerasakPing

Replace O(N) array scans (`some`) within the `sortedItems.map` rendering loop with O(1) Set lookups. Sets are computed using `useMemo` based on `selectedItems` and `clipboard` dependencies. This avoids O(N*M) complexity when rendering large directories with multiple selections or cut items.

Co-authored-by: TheerasakPing <185220419+TheerasakPing@users.noreply.github.com>
@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.

…I Fixes

Replace O(N) array scans (`some`) within the `sortedItems.map` rendering loop with O(1) Set lookups. Sets are computed using `useMemo` based on `selectedItems` and `clipboard` dependencies. This avoids O(N*M) complexity when rendering large directories with multiple selections or cut items.

Also includes fixes for Rust compilation warnings/errors detected by CI:
- Added missing `crate::log_info` macro import in tests
- Conditionally compiled macOS specific imports
- Removed unused `tauri::Manager` import
- Added `allow(unused_assignments)` to variables only used conditionally in loop structures

Co-authored-by: TheerasakPing <185220419+TheerasakPing@users.noreply.github.com>
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