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.
This commit is contained in:
kiyan 2022-07-29 09:35:15 +02:00
parent 7fcb48c852
commit 665813b9e6
2 changed files with 10 additions and 1 deletions

View File

@ -15,13 +15,13 @@ end
local function populate_children(handle, cwd, node, status)
local node_ignored = node.git_status == "!!"
local nodes_by_path = utils.bool_record(node.nodes, "absolute_path")
while true do
local name, t = uv.fs_scandir_next(handle)
if not name then
break
end
local nodes_by_path = utils.key_by(node.nodes, "absolute_path")
local abs = utils.path_join { cwd, name }
t = get_type_from(t, abs)
if
@ -42,6 +42,7 @@ local function populate_children(handle, cwd, node, status)
end
if child then
table.insert(node.nodes, child)
nodes_by_path[child.absolute_path] = true
common.update_git_status(child, node_ignored, status)
end
end

View File

@ -305,6 +305,14 @@ function M.key_by(tbl, key)
return keyed
end
function M.bool_record(tbl, key)
local keyed = {}
for _, val in ipairs(tbl) do
keyed[val[key]] = true
end
return keyed
end
local function timer_stop_close(timer)
if timer:is_active() then
timer:stop()