Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
'srefresh
function so now it accepts an optional argument calledmode
, Mode can be one of these options:The
normal
mode has identical behavior to the current revision of the NerdTree, theforce
mode will refresh the node no matter what state it has, and thelazyRefresh
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 modelazyRefresh
.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
MAJOR.MINOR.PATCH
version number. Increment the:MAJOR
version when you make incompatible API changesMINOR
version when you add functionality in a backwards-compatible mannerPATCH
version when you make backwards-compatible bug fixesCollaborator's Instructions