weirongxu / coc-explorer

📁 Explorer for coc.nvim
MIT License
1.14k stars 45 forks source link

[Feature] Don't try to scan all files on open #544

Closed Rizhiy closed 1 year ago

Rizhiy commented 2 years ago

Is your feature request related to a problem? Please describe. I have a project which has a data folder. There are quite a lot of files in the data folder ~500k When I first open coc-explorer, it takes something like 10 sec to open, which is annoying.

Describe the solution you'd like Since this doesn't happen in other project, I suspect the problem is that coc-explorer tries to build the whole file tree on first open. This seems pointless, since most of the time people don't even open most of their folders during normal use. Instead, the file tree should be evaluated lazily when each particular directory is expanded.

Describe alternatives you've considered I guess another solution would be to have some kind of ignore system, but that would require extra work on the part of a user, which is suboptimal.

weirongxu commented 2 years ago

The explorer doesn't read file contents when opening a directory. and doesn't traverse all the folders, it only traverses them when user use gl to expand them.

But I suspect that reading file information will cause slower loading (like link, executable, writable, readable).

I have to refactor this part of the code to make the explorer support lazy loading of this information.

Perhaps related #535

Rizhiy commented 2 years ago

My data is actually 4 folders deep from the root directory, so something is being done recursively.

When I'm in the root directory, most commands are very quick, here are the timings:

Rizhiy commented 2 years ago

I made a quick script which should reproduce the problem:

mkdir explorer-test
cd explorer-test
mkdir -p dir1/dir2/dir3/dir4
for idx in {1..100000}; do
    touch dir1/dir2/dir3/dir4/"$idx".txt
done
touch tmp.txt
vim tmp.txt

As mentioned in #535, vim freezes on first open. But if you close (^C) it and open vim again, it works normally but explorer takes a long time to open.

weirongxu commented 1 year ago

Sorry for the delay in replying. do you mean it will freeze when expanding dir1?

This is a feature that automatically expands a single folder. You can avoid expanding single directories by set explorer.autoExpandMaxDepth to 1, or set explorer.autoExpandOptions to []

Rizhiy commented 1 year ago

No, it freezes when I open explorer.

weirongxu commented 1 year ago

I made a quick script which should reproduce the problem:

mkdir explorer-test
cd explorer-test
mkdir -p dir1/dir2/dir3/dir4
for idx in {1..100000}; do
    touch dir1/dir2/dir3/dir4/"$idx".txt
done
touch tmp.txt
vim tmp.txt

As mentioned in #535, vim freezes on first open. But if you close (^C) it and open vim again, it works normally but explorer takes a long time to open.

I tried this shell script, but couldn't reproduce your problem. explorer needs to wait until coc.nvim is loaded before it can be opened, It is possible that coc.nvm or coc's extension is scanning the file tree, so coc is loading too slowly.

Rizhiy commented 1 year ago

I have updated all of my plugins and the problem fixed itself. Must have been something else.