Skip to content

Commit

Permalink
perf: reset packpath to only include the lazy package. Improved my st…
Browse files Browse the repository at this point in the history
…artup time by 2ms
  • Loading branch information
folke committed Dec 1, 2022
1 parent 5134e79 commit 4653119
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
13 changes: 12 additions & 1 deletion lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ M.defaults = {
version = nil,
-- version = "*", -- enable this to try installing the latest stable versions of plugins
},
packpath = vim.fn.stdpath("data") .. "/site/pack/lazy", -- package path where new plugins will be installed
lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
install_missing = true, -- install missing plugins on startup. This doesn't increase startup time.
concurrency = nil, -- set to a number to limit the maximum amount of concurrent tasks
Expand All @@ -20,6 +19,11 @@ M.defaults = {
log = { "--since=1 days ago" }, -- commits from the last 3 days
timeout = 120, -- processes taking over 2 minutes will be killed
},
package = {
path = vim.fn.stdpath("data") .. "/site",
name = "lazy", -- plugins will be installed under package.path/pack/{name}/opt
reset = true, -- packpath will be reset to only include lazy. This makes packadd a lot faster
},
-- Any plugin spec that contains one of the patterns will use your
-- local repo in the projects folder instead of fetchig it from github
-- Mostly useful for plugin developers.
Expand Down Expand Up @@ -49,6 +53,8 @@ M.defaults = {
M.ns = vim.api.nvim_create_namespace("lazy")

M.paths = {
---@type string
opt = nil,
---@type string
main = nil,
---@type string
Expand All @@ -69,6 +75,11 @@ function M.setup(opts)
M.options = vim.tbl_deep_extend("force", M.defaults, opts or {})
M.paths.plugins = vim.fn.stdpath("config") .. "/lua/" .. M.options.plugins:gsub("%.", "/")
M.paths.main = M.paths.plugins .. (vim.loop.fs_stat(M.paths.plugins .. ".lua") and ".lua" or "/init.lua")
M.paths.opt = M.options.package.path .. "/pack/" .. M.options.package.name .. "/opt"

if M.options.package.reset then
vim.go.packpath = M.options.package.path
end

vim.api.nvim_create_autocmd("User", {
pattern = "VeryLazy",
Expand Down
6 changes: 3 additions & 3 deletions lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ end
function M.update_state()
---@type table<string,FileType>
local installed = {}
Util.ls(Config.options.packpath .. "/opt", function(_, name, type)
Util.ls(Config.paths.opt, function(_, name, type)
if type == "directory" or type == "link" then
installed[name] = type
end
Expand All @@ -165,7 +165,7 @@ function M.update_state()
or plugin.cmd
plugin.lazy = lazy and true or false
end
plugin.dir = Config.options.packpath .. "/opt/" .. plugin.name
plugin.dir = Config.paths.opt .. "/" .. plugin.name
plugin._.is_local = plugin.uri:sub(1, 4) ~= "http" and plugin.uri:sub(1, 3) ~= "git"
plugin._.is_symlink = installed[plugin.name] == "link"
plugin._.installed = installed[plugin.name] ~= nil
Expand All @@ -178,7 +178,7 @@ function M.update_state()
for pack, dir_type in pairs(installed) do
table.insert(Config.to_clean, {
name = pack,
dir = Config.options.packpath .. "/opt/" .. pack,
dir = Config.paths.opt .. "/" .. pack,
_ = {
installed = true,
is_symlink = dir_type == "link",
Expand Down
4 changes: 2 additions & 2 deletions lua/lazy/core/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function M.try(fn, msg)
end
if info.what == "Lua" and not info.source:find("lazy.nvim") then
local source = info.source:sub(2)
if source:find(Config.options.packpath, 1, true) == 1 then
source = source:sub(#Config.options.packpath + 1):gsub("^/opt/", ""):gsub("^/start/", "")
if source:find(Config.paths.opt, 1, true) == 1 then
source = source:sub(#Config.paths.opt + 1)
end
source = vim.fn.fnamemodify(source, ":p:~:.")
local line = " - " .. source .. ":" .. info.currentline
Expand Down

0 comments on commit 4653119

Please sign in to comment.