-
Notifications
You must be signed in to change notification settings - Fork 255
Async scan is blocking? #609
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
Comments
Looked through it again, and it seems that it uses that async API from luv, so I'm not sure why it blocks. |
If you look here: https://github.com/nvim-neo-tree/neo-tree.nvim/wiki/Troubleshooting It will describe how to enable logging. You can then tail the log file in a separate window for clues as to what is happening during the hang. It's always possible that the hang is from some other plugin that is responding to the new text being added to the buffer. |
It is possible that checking git ignore is the hang. Is the large directory a git project? |
No, it was a plain directory of ~/Downloads. Aren't git operations supposed to be async by default anyways? |
I also tried to log it, and I can't really find any thing suspicious, but I snipped some parts where there is a big gap between the log times:
|
Are you on Windows? |
Yes, I'm on Windows. |
Alright, I figured out the problem. Rough patchlocal function async_scan(context, path)
log.trace("async_scan: ", path)
-- prepend the root path
table.insert(context.paths_to_load, 1, path)
context.directories_scanned = 0
context.directories_to_scan = #context.paths_to_load
context.on_exit = vim.schedule_wrap(function()
job_complete(context)
end)
-- from https://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/scandir.lua
local function read_dir(current_dir, ctx)
local function on_fs_opendir(err, dir)
if err then
log.error(current_dir, ": ", err)
else
local function on_fs_readdir(err, entries)
if err then
log.error(current_dir, ": ", err)
else
if entries then
for _, entry in ipairs(entries) do
local success, item = pcall(
file_items.create_item,
ctx,
utils.path_join(current_dir, entry.name),
entry.type
)
if success then
if ctx.recursive and item.type == "directory" then
ctx.directories_to_scan = ctx.directories_to_scan + 1
table.insert(ctx.paths_to_load, item.path)
end
else
log.error("error creating item for ", path)
end
end
uv.fs_readdir(dir, on_fs_readdir)
else
uv.fs_closedir(dir)
on_directory_loaded(ctx, current_dir)
ctx.directories_scanned = ctx.directories_scanned + 1
if ctx.directories_scanned == #ctx.paths_to_load then
ctx.on_exit()
end
end
end
end
uv.fs_readdir(dir, on_fs_readdir)
end
end
uv.fs_opendir(current_dir, on_fs_opendir)
end
for i = 1, context.directories_to_scan do
read_dir(context.paths_to_load[i], context)
end
end |
Huh. I think that the original implementation allowed other work in between because it scanned one folder at a time in a chain. So it wasn't fully async, but effectively good enough. Then it was changed to scan them in parallel to make the whole process faster, which accidentally caused it to be effectively blocking. Anyway, good catch! Please do submit a PR if you have the time. |
Replace `uv.fs_scandir` and `uv.fs_scandir_next` with their async alternatives, `uv.fs_opendir` and `uv.fs_readdir` Fix: #609
I have
async_directory_scan
set toalways
in my configuration, but toggling a neo-tree window still blocks neovim for me.I tested by opening neo-tree in a very large directory on my slow hard drive, and neovim blocks, until the neo-tree window is fully rendered.
I looked through the code for async_scan, but it seems completely synchronous to me.
Anything I'm missing here?
The text was updated successfully, but these errors were encountered: