feat(profiling): added options to enable additional profiling

This commit is contained in:
Folke Lemaitre 2023-10-09 12:38:43 +02:00
parent ce3e8523de
commit 423a152e94
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
6 changed files with 102 additions and 60 deletions

View file

@ -65,6 +65,7 @@ M.defaults = {
not_loaded = "",
plugin = "",
runtime = "",
require = "󰢱 ",
source = "",
start = "",
task = "",
@ -158,6 +159,15 @@ M.defaults = {
-- executed. In this case, a warning message will be shown.
warn_on_override = true,
},
-- Enable profiling of lazy.nvim. This will add some overhead,
-- so only enable this when you are debugging lazy.nvim
profiling = {
-- Enables extra stats on the debug tab related to the loader cache.
-- Additionally gathers stats about all package.loaders
loader = false,
-- Track each new require in the Lazy profiling tab
require = false,
},
debug = false,
}

View file

@ -118,7 +118,7 @@ function M.get_source()
if not info then
break
end
if info.what ~= "C" and not info.source:find("lazy.nvim", 1, true) then
if info.what ~= "C" and not info.source:find("lazy.nvim", 1, true) and info.source ~= "@vim/loader.lua" then
return info.source:sub(2)
end
f = f + 1

View file

@ -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

View file

@ -26,6 +26,7 @@ M.colors = {
ReasonFt = "Character",
ReasonCmd = "Operator",
ReasonImport = "Identifier",
ReasonRequire = "@parameter",
Button = "CursorLine",
ButtonActive = "Visual",
TaskOutput = "MsgArea", -- task output

View file

@ -320,7 +320,7 @@ function M:reason(reason, opts)
for _, key in ipairs(keys) do
local value = reason[key]
if type(key) == "number" then
elseif key == "require" then
-- elseif key == "require" then
elseif key ~= "time" then
if first then
first = false