Skip to content

Commit 665813b

Browse files
committed
fix(perf): explorer was creating new table for each new entry
augment performance on large folder by a factor of 10. my /nix/store explorer goes from ~12sec to ~1.5sec.
1 parent 7fcb48c commit 665813b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lua/nvim-tree/explorer/explore.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ end
1515

1616
local function populate_children(handle, cwd, node, status)
1717
local node_ignored = node.git_status == "!!"
18+
local nodes_by_path = utils.bool_record(node.nodes, "absolute_path")
1819
while true do
1920
local name, t = uv.fs_scandir_next(handle)
2021
if not name then
2122
break
2223
end
2324

24-
local nodes_by_path = utils.key_by(node.nodes, "absolute_path")
2525
local abs = utils.path_join { cwd, name }
2626
t = get_type_from(t, abs)
2727
if
@@ -42,6 +42,7 @@ local function populate_children(handle, cwd, node, status)
4242
end
4343
if child then
4444
table.insert(node.nodes, child)
45+
nodes_by_path[child.absolute_path] = true
4546
common.update_git_status(child, node_ignored, status)
4647
end
4748
end

lua/nvim-tree/utils.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ function M.key_by(tbl, key)
305305
return keyed
306306
end
307307

308+
function M.bool_record(tbl, key)
309+
local keyed = {}
310+
for _, val in ipairs(tbl) do
311+
keyed[val[key]] = true
312+
end
313+
return keyed
314+
end
315+
308316
local function timer_stop_close(timer)
309317
if timer:is_active() then
310318
timer:stop()

0 commit comments

Comments
 (0)