Skip to content

Commit

Permalink
feat(profiling): added options to enable additional profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Oct 9, 2023
1 parent ce3e852 commit 423a152
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 60 deletions.
111 changes: 61 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ return {
not_loaded = "",
plugin = "",
runtime = "",
require = "󰢱 ",
source = "",
start = "",
task = "",
Expand Down Expand Up @@ -448,6 +449,15 @@ return {
-- 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,
},
}
```

Expand Down Expand Up @@ -495,24 +505,24 @@ Any operation can be started from the UI, with a sub command or an API function:

<!-- commands:start -->

| Command | Lua | Description |
| ------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `:Lazy build {plugins}` | `require("lazy").build(opts)` | Rebuild a plugin |
| `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) |
| `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed |
| `:Lazy clear` | `require("lazy").clear()` | Clear finished tasks |
| `:Lazy debug` | `require("lazy").debug()` | Show debug information |
| `:Lazy health` | `require("lazy").health()` | Run `:checkhealth lazy` |
| `:Lazy help` | `require("lazy").help()` | Toggle this help page |
| `:Lazy home` | `require("lazy").home()` | Go back to plugin list |
| `:Lazy install [plugins]` | `require("lazy").install(opts?)` | Install missing plugins |
| `:Lazy load {plugins}` | `require("lazy").load(opts)` | Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim`. Use `:Lazy! load` to skip `cond` checks. |
| `:Lazy log [plugins]` | `require("lazy").log(opts?)` | Show recent updates |
| `:Lazy profile` | `require("lazy").profile()` | Show detailed profiling |
| `:Lazy reload {plugins}` | `require("lazy").reload(opts)` | Reload a plugin (experimental!!) |
| Command | Lua | Description |
| --- | --- | --- | --- |
| `:Lazy build {plugins}` | `require("lazy").build(opts)` | Rebuild a plugin |
| `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) |
| `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed |
| `:Lazy clear` | `require("lazy").clear()` | Clear finished tasks |
| `:Lazy debug` | `require("lazy").debug()` | Show debug information |
| `:Lazy health` | `require("lazy").health()` | Run `:checkhealth lazy` |
| `:Lazy help` | `require("lazy").help()` | Toggle this help page |
| `:Lazy home` | `require("lazy").home()` | Go back to plugin list |
| `:Lazy install [plugins]` | `require("lazy").install(opts?)` | Install missing plugins |
| `:Lazy load {plugins}` | `require("lazy").load(opts)` | Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim`. Use `:Lazy! load` to skip `cond` checks. |
| `:Lazy log [plugins]` | `require("lazy").log(opts?)` | Show recent updates |
| `:Lazy profile` | `require("lazy").profile()` | Show detailed profiling |
| `:Lazy reload {plugins}` | `require("lazy").reload(opts)` | Reload a plugin (experimental!!) |
| `:Lazy restore [plugins]` | `require("lazy").restore(opts?)` | Updates all plugins to the state in the lockfile. For a single plugin: restore it to the state in the lockfile or to a given commit under the cursor |
| `:Lazy sync [plugins]` | `require("lazy").sync(opts?)` | Run install, clean and update |
| `:Lazy update [plugins]` | `require("lazy").update(opts?)` | Update plugins. This will also update the lockfile |
| `:Lazy sync [plugins]` | `require("lazy").sync(opts?)` | Run install, clean and update |
| `:Lazy update [plugins]` | `require("lazy").update(opts?)` | Update plugins. This will also update the lockfile |

<!-- commands:end -->

Expand Down Expand Up @@ -763,39 +773,40 @@ To uninstall **lazy.nvim**, you need to remove the following files and directori

<!-- colors:start -->

| Highlight Group | Default Group | Description |
| --------------------- | -------------------------- | --------------------------------------------------- |
| **LazyButton** | **_CursorLine_** | |
| **LazyButtonActive** | **_Visual_** | |
| **LazyComment** | **_Comment_** | |
| **LazyCommit** | **_@variable.builtin_** | commit ref |
| **LazyCommitIssue** | **_Number_** | |
| **LazyCommitScope** | **_Italic_** | conventional commit scope |
| **LazyCommitType** | **_Title_** | conventional commit type |
| **LazyDimmed** | **_Conceal_** | property |
| **LazyDir** | **_@text.reference_** | directory |
| **LazyH1** | **_IncSearch_** | home button |
| **LazyH2** | **_Bold_** | titles |
| **LazyLocal** | **_Constant_** | |
| **LazyNoCond** | **_DiagnosticWarn_** | unloaded icon for a plugin where `cond()` was false |
| **LazyNormal** | **_NormalFloat_** | |
| **LazyProgressDone** | **_Constant_** | progress bar done |
| **LazyProgressTodo** | **_LineNr_** | progress bar todo |
| **LazyProp** | **_Conceal_** | property |
| **LazyReasonCmd** | **_Operator_** | |
| **LazyReasonEvent** | **_Constant_** | |
| **LazyReasonFt** | **_Character_** | |
| **LazyReasonImport** | **_Identifier_** | |
| **LazyReasonKeys** | **_Statement_** | |
| **LazyReasonPlugin** | **_Special_** | |
| **LazyReasonRuntime** | **_@macro_** | |
| **LazyReasonSource** | **_Character_** | |
| **LazyReasonStart** | **_@field_** | |
| **LazySpecial** | **_@punctuation.special_** | |
| **LazyTaskError** | **_ErrorMsg_** | task errors |
| **LazyTaskOutput** | **_MsgArea_** | task output |
| **LazyUrl** | **_@text.reference_** | url |
| **LazyValue** | **_@string_** | value of a property |
| Highlight Group | Default Group | Description |
| --- | --- | --- |
| **LazyButton** | ***CursorLine*** | |
| **LazyButtonActive** | ***Visual*** | |
| **LazyComment** | ***Comment*** | |
| **LazyCommit** | ***@variable.builtin*** | commit ref |
| **LazyCommitIssue** | ***Number*** | |
| **LazyCommitScope** | ***Italic*** | conventional commit scope |
| **LazyCommitType** | ***Title*** | conventional commit type |
| **LazyDimmed** | ***Conceal*** | property |
| **LazyDir** | ***@text.reference*** | directory |
| **LazyH1** | ***IncSearch*** | home button |
| **LazyH2** | ***Bold*** | titles |
| **LazyLocal** | ***Constant*** | |
| **LazyNoCond** | ***DiagnosticWarn*** | unloaded icon for a plugin where `cond()` was false |
| **LazyNormal** | ***NormalFloat*** | |
| **LazyProgressDone** | ***Constant*** | progress bar done |
| **LazyProgressTodo** | ***LineNr*** | progress bar todo |
| **LazyProp** | ***Conceal*** | property |
| **LazyReasonCmd** | ***Operator*** | |
| **LazyReasonEvent** | ***Constant*** | |
| **LazyReasonFt** | ***Character*** | |
| **LazyReasonImport** | ***Identifier*** | |
| **LazyReasonKeys** | ***Statement*** | |
| **LazyReasonPlugin** | ***Special*** | |
| **LazyReasonRequire** | ***@parameter*** | |
| **LazyReasonRuntime** | ***@macro*** | |
| **LazyReasonSource** | ***Character*** | |
| **LazyReasonStart** | ***@field*** | |
| **LazySpecial** | ***@punctuation.special*** | |
| **LazyTaskError** | ***ErrorMsg*** | task errors |
| **LazyTaskOutput** | ***MsgArea*** | task output |
| **LazyUrl** | ***@text.reference*** | url |
| **LazyValue** | ***@string*** | value of a property |

<!-- colors:end -->

Expand Down
10 changes: 10 additions & 0 deletions lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ M.defaults = {
not_loaded = "",
plugin = "",
runtime = "",
require = "󰢱 ",
source = "",
start = "",
task = "",
Expand Down Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion lua/lazy/core/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 28 additions & 8 deletions lua/lazy/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/lazy/view/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ M.colors = {
ReasonFt = "Character",
ReasonCmd = "Operator",
ReasonImport = "Identifier",
ReasonRequire = "@parameter",
Button = "CursorLine",
ButtonActive = "Visual",
TaskOutput = "MsgArea", -- task output
Expand Down
2 changes: 1 addition & 1 deletion lua/lazy/view/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 423a152

Please sign in to comment.