Skip to content

Commit 4653119

Browse files
committed
perf: reset packpath to only include the lazy package. Improved my startup time by 2ms
1 parent 5134e79 commit 4653119

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

lua/lazy/core/config.lua

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ M.defaults = {
1010
version = nil,
1111
-- version = "*", -- enable this to try installing the latest stable versions of plugins
1212
},
13-
packpath = vim.fn.stdpath("data") .. "/site/pack/lazy", -- package path where new plugins will be installed
1413
lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
1514
install_missing = true, -- install missing plugins on startup. This doesn't increase startup time.
1615
concurrency = nil, -- set to a number to limit the maximum amount of concurrent tasks
@@ -20,6 +19,11 @@ M.defaults = {
2019
log = { "--since=1 days ago" }, -- commits from the last 3 days
2120
timeout = 120, -- processes taking over 2 minutes will be killed
2221
},
22+
package = {
23+
path = vim.fn.stdpath("data") .. "/site",
24+
name = "lazy", -- plugins will be installed under package.path/pack/{name}/opt
25+
reset = true, -- packpath will be reset to only include lazy. This makes packadd a lot faster
26+
},
2327
-- Any plugin spec that contains one of the patterns will use your
2428
-- local repo in the projects folder instead of fetchig it from github
2529
-- Mostly useful for plugin developers.
@@ -49,6 +53,8 @@ M.defaults = {
4953
M.ns = vim.api.nvim_create_namespace("lazy")
5054

5155
M.paths = {
56+
---@type string
57+
opt = nil,
5258
---@type string
5359
main = nil,
5460
---@type string
@@ -69,6 +75,11 @@ function M.setup(opts)
6975
M.options = vim.tbl_deep_extend("force", M.defaults, opts or {})
7076
M.paths.plugins = vim.fn.stdpath("config") .. "/lua/" .. M.options.plugins:gsub("%.", "/")
7177
M.paths.main = M.paths.plugins .. (vim.loop.fs_stat(M.paths.plugins .. ".lua") and ".lua" or "/init.lua")
78+
M.paths.opt = M.options.package.path .. "/pack/" .. M.options.package.name .. "/opt"
79+
80+
if M.options.package.reset then
81+
vim.go.packpath = M.options.package.path
82+
end
7283

7384
vim.api.nvim_create_autocmd("User", {
7485
pattern = "VeryLazy",

lua/lazy/core/plugin.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ end
147147
function M.update_state()
148148
---@type table<string,FileType>
149149
local installed = {}
150-
Util.ls(Config.options.packpath .. "/opt", function(_, name, type)
150+
Util.ls(Config.paths.opt, function(_, name, type)
151151
if type == "directory" or type == "link" then
152152
installed[name] = type
153153
end
@@ -165,7 +165,7 @@ function M.update_state()
165165
or plugin.cmd
166166
plugin.lazy = lazy and true or false
167167
end
168-
plugin.dir = Config.options.packpath .. "/opt/" .. plugin.name
168+
plugin.dir = Config.paths.opt .. "/" .. plugin.name
169169
plugin._.is_local = plugin.uri:sub(1, 4) ~= "http" and plugin.uri:sub(1, 3) ~= "git"
170170
plugin._.is_symlink = installed[plugin.name] == "link"
171171
plugin._.installed = installed[plugin.name] ~= nil
@@ -178,7 +178,7 @@ function M.update_state()
178178
for pack, dir_type in pairs(installed) do
179179
table.insert(Config.to_clean, {
180180
name = pack,
181-
dir = Config.options.packpath .. "/opt/" .. pack,
181+
dir = Config.paths.opt .. "/" .. pack,
182182
_ = {
183183
installed = true,
184184
is_symlink = dir_type == "link",

lua/lazy/core/util.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function M.try(fn, msg)
4040
end
4141
if info.what == "Lua" and not info.source:find("lazy.nvim") then
4242
local source = info.source:sub(2)
43-
if source:find(Config.options.packpath, 1, true) == 1 then
44-
source = source:sub(#Config.options.packpath + 1):gsub("^/opt/", ""):gsub("^/start/", "")
43+
if source:find(Config.paths.opt, 1, true) == 1 then
44+
source = source:sub(#Config.paths.opt + 1)
4545
end
4646
source = vim.fn.fnamemodify(source, ":p:~:.")
4747
local line = " - " .. source .. ":" .. info.currentline

0 commit comments

Comments
 (0)