mirror of
				https://github.com/folke/lazy.nvim.git
				synced 2025-11-04 00:11:06 +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
				
			
		| 
						 | 
				
			
			@ -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,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,6 +26,7 @@ M.colors = {
 | 
			
		|||
  ReasonFt = "Character",
 | 
			
		||||
  ReasonCmd = "Operator",
 | 
			
		||||
  ReasonImport = "Identifier",
 | 
			
		||||
  ReasonRequire = "@parameter",
 | 
			
		||||
  Button = "CursorLine",
 | 
			
		||||
  ButtonActive = "Visual",
 | 
			
		||||
  TaskOutput = "MsgArea", -- task output
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue