Skip to content

Commit 3ec5a2c

Browse files
committed
perf: run cache autosave after loading
1 parent e6bbf92 commit 3ec5a2c

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

lua/lazy/core/cache.lua

+24-25
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,30 @@ function M.hash(file)
4444
end
4545

4646
function M.setup()
47-
M.load()
47+
cache = {}
48+
local f = io.open(cache_path, "rb")
49+
if f then
50+
cache_hash = M.hash(cache_path)
51+
---@type string
52+
local data = f:read("*a")
53+
f:close()
54+
55+
local from = 1
56+
local to = data:find("\0", from, true)
57+
while to do
58+
local key = data:sub(from, to - 1)
59+
from = to + 1
60+
to = data:find("\0", from, true)
61+
local len = tonumber(data:sub(from, to - 1))
62+
from = to + 1
63+
cache[key] = data:sub(from, from + len - 1)
64+
from = from + len
65+
to = data:find("\0", from, true)
66+
end
67+
end
68+
end
69+
70+
function M.autosave()
4871
vim.api.nvim_create_autocmd("User", {
4972
pattern = "LazyDone",
5073
once = true,
@@ -77,28 +100,4 @@ function M.save()
77100
f:close()
78101
end
79102

80-
function M.load()
81-
cache = {}
82-
local f = io.open(cache_path, "rb")
83-
if f then
84-
cache_hash = M.hash(cache_path)
85-
---@type string
86-
local data = f:read("*a")
87-
f:close()
88-
89-
local from = 1
90-
local to = data:find("\0", from, true)
91-
while to do
92-
local key = data:sub(from, to - 1)
93-
from = to + 1
94-
to = data:find("\0", from, true)
95-
local len = tonumber(data:sub(from, to - 1))
96-
from = to + 1
97-
cache[key] = data:sub(from, from + len - 1)
98-
from = from + len
99-
to = data:find("\0", from, true)
100-
end
101-
end
102-
end
103-
104103
return M

lua/lazy/core/config.lua

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ M.defaults = {
2727
task = "",
2828
},
2929
},
30+
install_missing = true,
3031
git = {
3132
-- defaults for `Lazy log`
3233
log = { "-10" }, -- last 10 commits
@@ -67,6 +68,7 @@ function M.setup(opts)
6768
pattern = "VeryLazy",
6869
once = true,
6970
callback = function()
71+
require("lazy.core.cache").autosave()
7072
require("lazy.view").setup()
7173
end,
7274
})

0 commit comments

Comments
 (0)