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:
@@ -15,13 +15,13 @@ end
|
|||||||
|
|
||||||
local function populate_children(handle, cwd, node, status)
|
local function populate_children(handle, cwd, node, status)
|
||||||
local node_ignored = node.git_status == "!!"
|
local node_ignored = node.git_status == "!!"
|
||||||
|
local nodes_by_path = utils.bool_record(node.nodes, "absolute_path")
|
||||||
while true do
|
while true do
|
||||||
local name, t = uv.fs_scandir_next(handle)
|
local name, t = uv.fs_scandir_next(handle)
|
||||||
if not name then
|
if not name then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
local nodes_by_path = utils.key_by(node.nodes, "absolute_path")
|
|
||||||
local abs = utils.path_join { cwd, name }
|
local abs = utils.path_join { cwd, name }
|
||||||
t = get_type_from(t, abs)
|
t = get_type_from(t, abs)
|
||||||
if
|
if
|
||||||
@@ -42,6 +42,7 @@ local function populate_children(handle, cwd, node, status)
|
|||||||
end
|
end
|
||||||
if child then
|
if child then
|
||||||
table.insert(node.nodes, child)
|
table.insert(node.nodes, child)
|
||||||
|
nodes_by_path[child.absolute_path] = true
|
||||||
common.update_git_status(child, node_ignored, status)
|
common.update_git_status(child, node_ignored, status)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -305,6 +305,14 @@ function M.key_by(tbl, key)
|
|||||||
return keyed
|
return keyed
|
||||||
end
|
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)
|
local function timer_stop_close(timer)
|
||||||
if timer:is_active() then
|
if timer:is_active() then
|
||||||
timer:stop()
|
timer:stop()
|
||||||
|
|||||||
Reference in New Issue
Block a user