mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-18 20:36:45 +00:00
perf: move autoloader to cache and always use lazy's modname path resolver which is much faster
This commit is contained in:
parent
956164d27d
commit
34977c2b80
5 changed files with 128 additions and 54 deletions
|
@ -28,9 +28,6 @@ function M.setup()
|
|||
end,
|
||||
})
|
||||
|
||||
-- autoload opt plugins
|
||||
table.insert(package.loaders, M.autoload)
|
||||
|
||||
-- install missing plugins
|
||||
if Config.options.install.missing then
|
||||
Util.track("install")
|
||||
|
@ -298,32 +295,4 @@ function M.colorscheme(name)
|
|||
end
|
||||
end
|
||||
|
||||
-- This loader is added as the very last one.
|
||||
-- This only hits when the modname is not cached and
|
||||
-- even then only once per plugin. So pretty much never.
|
||||
---@param modname string
|
||||
function M.autoload(modname)
|
||||
-- check if a lazy plugin should be loaded
|
||||
for _, plugin in pairs(Config.plugins) do
|
||||
if not (plugin._.loaded or plugin.module == false) then
|
||||
for _, pattern in ipairs({ ".lua", "/init.lua" }) do
|
||||
local path = plugin.dir .. "/lua/" .. modname:gsub("%.", "/") .. pattern
|
||||
if vim.loop.fs_stat(path) then
|
||||
M.load(plugin, { require = modname })
|
||||
-- check if the module has been loaded in the meantime
|
||||
if type(package.loaded[modname]) == "table" then
|
||||
local mod = package.loaded[modname]
|
||||
return function()
|
||||
return mod
|
||||
end
|
||||
end
|
||||
local chunk, err = loadfile(path)
|
||||
return chunk or error(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return modname .. " not found in lazy plugins"
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue