coteditor / CotEditor

Lightweight Plain-Text Editor for macOS
https://coteditor.com
Other
6.37k stars 433 forks source link

When opening and closing folders with many files in the sidebar, it takes longer than it should. #1711

Open kishikawakatsumi opened 1 week ago

kishikawakatsumi commented 1 week ago

Description

When opening and closing folders with many files (2000 files for debug builds, 4000 to 8000 for release builds to reproduce) in the sidebar, it takes longer than expected.

https://github.com/user-attachments/assets/75cab0b0-18d4-48ce-9028-b9b7e2e69c12

This is because NSOutlineView calls outlineView(_:child:ofItem:) (and related functions) for ALL elements.

When an element is expanded or collapsed, contrary to our intuition, NSOutlineView calls the delegate method for all elements, not just the visible ones, (presumably to maintain the element's expanded/collapsed state).

So delegate methods called at this time needs to complete as quickly as possible.

In this case I recommend using a very short term cache that is only valid while element expansion or collapse operation.

To Reproduce

  1. Create a directory named test
  2. Create many files in the directory. e.g. touch test{0001..2000}.dat
  3. Open the parent directory of the test directory.
  4. Expand/collapse test directory in the sidebar.

Expected behavior

The time taken to expand and collapse folders is not proportional to the amount of files.

CotEditor version

Version 5.0.0-rc (666)

macOS version

14.6.1 (23G93)

Additional context

No response

1024jp commented 1 week ago

Thank you for the feedback. Well, that needs to be improved.

In this case I recommend using a very short term cache that is only valid while element expansion or collapse operation.

Thank you even for the recommendation. However, I feel it's a bit dangerous when the user expands multiple folders at once (with the Option+ shortcut). It, of course, depends on where and how we make the cache, though.

Looking ahead to future features like file filtering, I now feel it's better to have another tree (or children) only for the presentation. Let me think.