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

Lazy Directory Refresh #1362

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Lazy Directory Refresh #1362

wants to merge 5 commits into from

Conversation

rzvxa
Copy link
Member

@rzvxa rzvxa commented Aug 21, 2023

Description of Changes

Added a new feature for helping with the performance via lazy loading.
Right now NerdTree is keeping track of every directory that has ever been opened And will refresh them when a refresh happens via NERDTreeMapRefresh, This approach is perfect for small to medium code bases, But my day job forces me to work on substantial monolith repositories, It makes NerdTree very slow to use whenever you open a big directory. The initial caching process understandably takes time and by the look of the NerdTree structure it seems going full async is going to be very time-consuming as it is built before any vim-script async options and implementing asynchronous tree manipulation is going to need major refactoring.
So best solution for now is going to be doing optimization where it is possible, My first try to tackle this problem is lazy loading for directories. In this PR I've modified TreeDirNode's refresh function so now it accepts an optional argument called mode, Mode can be one of these options:

    0 == normal (default when nothing passed)
    1 == force
    2 == lazyRefresh

The normal mode has identical behavior to the current revision of the NerdTree, the force mode will refresh the node no matter what state it has, and the lazyRefresh state will refresh the node only if its lazyRefresh flag has been set before.

Whenever a normal refresh is performed which means every old call of refresh, We check if NerdTreeLazyDirRefresh is set or not, If its set then we only perform refresh on already open directories, And mark closed directories for lazyRefresh, Then at any point which TreeDirNode's data is needed we perform refresh with mode lazyRefresh.

This way when you are working on a big project, Or even want to open a directory like node_modules containing many nested directories, After the initial caching which is going to be slow, You can browse the directory and close its tree afterward to regain your performance, Now if you perform a refresh on the root of project, Huge directory will only get marked for refresh next time you are going to open it Instead of doing it immediately.

Potential problems

There may or may not be some usages of TreeDirNode which need its data updated but I haven't used lazyRefresh there, I haven't encountered any problems yet, But I don't use every functionality of NerdTree in my workflow and I don't have a deep knowledge of NerdTree codebase. Hence experimental flag is there in the documentation to warn people.

Demonstration

Here is a short side-by-side video of the difference between this feature enable or disable.

nerdtree-lazy-children-demonstration.mp4

New Version Info

Author's Instructions

  • Derive a new MAJOR.MINOR.PATCH version number. Increment the:
    • MAJOR version when you make incompatible API changes
    • MINOR version when you add functionality in a backwards-compatible manner
    • PATCH version when you make backwards-compatible bug fixes
  • Update CHANGELOG.md, following the established pattern.

Collaborator's Instructions

  • Review CHANGELOG.md, suggesting a different version number if necessary.
  • After merging, tag the commit using these (Mac-compatible) bash commands:
    git checkout master
    git pull
    sed -n "$(grep -n -m2 '####' CHANGELOG.md | cut -f1 -d: | sed 'N;s/\n/,/')p" CHANGELOG.md | sed '$d'
    git tag -a $(read -p "Tag Name: " tag;echo $tag) -m"$(git show --quiet --pretty=%s)";git push origin --tags

@rzvxa
Copy link
Member Author

rzvxa commented Aug 21, 2023

Doesn't fix but helps with #1357

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant