Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project sidebar loading optimisation #686

Conversation

KaiTheRedNinja
Copy link
Contributor

@KaiTheRedNinja KaiTheRedNinja commented Jul 12, 2022

Description

TL;DR, I optimised the project navigator code so that dispatch sources (AKA watchers, the thing that listens for changes within folders) are only applied to visible folders, greatly reducing the number of watchers that need to be created. This reduces the chance of bumping into the macOS file opening limit (eg. 2559 on my system).

More details: When a folder is compressed, the watcher still stays activated. This is to avoid repeatedly creating and cancelling watchers, using up a lot of RAM. In the (now rare) case that there are no more open calls left (meaning more than 2559 items have been opened), the icon goes from folder or folder.fill to questionmark.folder to indicate that it is not being watched.

Related Issue

Checklist

  • Clean up code
  • Test on large project
  • I read and understood the contributing guide as well as the code of conduct
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • I documented my code
  • Review requested

Screenshots

example of a NextJS project (with node modules) successfully opened in CodeEdit, with enough open calls left to open a few tabs. Only the 13 folders visible here have watchers attached to them, making about 29 watchers in total (CodeEdit itself requires about 16 files open for miscellaneous purposes), well below the 2559 item file limit of my system.
image

@KaiTheRedNinja KaiTheRedNinja marked this pull request as ready for review July 13, 2022 01:43
@KaiTheRedNinja KaiTheRedNinja changed the title [WIP] Project sidebar loading optimisation Project sidebar loading optimisation Jul 13, 2022
@KaiTheRedNinja
Copy link
Contributor Author

In CodeEditModules/Modules/WorkspaceClient/src/Model/FileItem.swift, I have updated the image property again so that in the rare case that CodeEdit runs into the file limit, the default file icon is replaced by questionmark.folder to indicate that it is not being watched.

@KaiTheRedNinja
Copy link
Contributor Author

KaiTheRedNinja commented Jul 13, 2022

image

for those interested, the number in this mock-up represents the file id of that file. When any of the folders are expanded, their child files will take the IDs of 20, 21, etc.

14 and 15 have a lower number than 16 despite being a layer lower because the watcher function relies on the order in which the FileItems are rendered in the OutlineView, and 13 was already expanded the last time I opened the workspace. These numbers are given out again when CodeEdit restarts, from top to bottom.

0xWDG
0xWDG previously approved these changes Jul 13, 2022
@Matejkob
Copy link
Collaborator

I'm on it

Copy link
Collaborator

@Matejkob Matejkob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to say that your solution to fix this issue impressed me. Watching only visible items is pretty clever! 🚀

CodeEditModules/Modules/WorkspaceClient/src/Live.swift Outdated Show resolved Hide resolved
CodeEditModules/Modules/WorkspaceClient/src/Live.swift Outdated Show resolved Hide resolved
@austincondiff austincondiff merged commit b2a0572 into CodeEditApp:main Jul 16, 2022
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.

4 participants