mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-20 05:16:45 +00:00
feat(profiling): added options to enable additional profiling
This commit is contained in:
parent
ce3e8523de
commit
423a152e94
6 changed files with 102 additions and 60 deletions
|
@ -2,6 +2,23 @@
|
|||
local M = {}
|
||||
M._start = 0
|
||||
|
||||
local function profile_require()
|
||||
local done = {} ---@type table<string, true>
|
||||
local r = require
|
||||
_G.require = function(modname)
|
||||
local Util = package.loaded["lazy.core.util"]
|
||||
if Util and not done[modname] then
|
||||
done[modname] = true
|
||||
Util.track({ require = modname })
|
||||
local ret = vim.F.pack_len(r(modname))
|
||||
Util.track()
|
||||
return vim.F.unpack_len(ret)
|
||||
else
|
||||
return r(modname)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@overload fun(opts: LazyConfig)
|
||||
---@overload fun(spec:LazySpec, opts: LazyConfig)
|
||||
function M.setup(spec, opts)
|
||||
|
@ -40,17 +57,16 @@ function M.setup(spec, opts)
|
|||
|
||||
local Cache = require("lazy.core.cache")
|
||||
|
||||
local enable_cache = not (
|
||||
opts
|
||||
and opts.performance
|
||||
and opts.performance.cache
|
||||
and opts.performance.cache.enabled == false
|
||||
)
|
||||
local enable_cache = vim.tbl_get(opts, "performance", "cache", "enabled") ~= false
|
||||
-- load module cache before anything else
|
||||
if enable_cache then
|
||||
Cache.enable()
|
||||
end
|
||||
|
||||
if vim.tbl_get(opts, "profiling", "require") then
|
||||
profile_require()
|
||||
end
|
||||
|
||||
require("lazy.stats").track("LazyStart")
|
||||
|
||||
local Util = require("lazy.core.util")
|
||||
|
@ -59,8 +75,12 @@ function M.setup(spec, opts)
|
|||
|
||||
table.insert(package.loaders, 3, Loader.loader)
|
||||
|
||||
if vim.g.profile_loaders then
|
||||
Cache.profile_loaders()
|
||||
if vim.tbl_get(opts, "profiling", "loader") then
|
||||
if vim.loader then
|
||||
vim.loader._profile({ loaders = true })
|
||||
else
|
||||
Cache._profile_loaders()
|
||||
end
|
||||
end
|
||||
|
||||
Util.track({ plugin = "lazy.nvim" }) -- setup start
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue