perf: split caching in state, cache and module

This commit is contained in:
Folke Lemaitre 2022-11-22 21:12:33 +01:00
parent a543134b8c
commit 54d5ff18f5
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
8 changed files with 455 additions and 395 deletions

View file

@ -2,31 +2,47 @@ local M = {}
---@param opts? LazyConfig
function M.setup(opts)
--FIXME: preload()
local done = false
-- table.insert(package.loaders, 1, function(modname)
-- if not done and modname:find("lazy") == 1 then
-- dd(modname)
-- end
-- end)
-- Loading order
-- 1. load module cache
-- 2. if changes, then reload
local Cache = require("lazy.cache")
local cache_start = vim.loop.hrtime()
require("lazy.core.cache").setup()
local start = vim.loop.hrtime()
Cache.boot()
local module_start = vim.loop.hrtime()
local Module = require("lazy.core.module").setup()
local require_start = vim.loop.hrtime()
local Util = require("lazy.util")
local Config = require("lazy.config")
local Plugin = require("lazy.plugin")
local Loader = require("lazy.loader")
local State = require("lazy.core.state")
Util.track("lazy_boot", vim.loop.hrtime() - start)
Util.track("cache.setup", module_start - cache_start)
Util.track("module.setup", require_start - module_start)
Util.track("require.core", vim.loop.hrtime() - require_start)
Util.track("lazy_setup")
Util.track("setup")
Util.track("lazy_config")
Util.track("config")
Config.setup(opts)
Util.track()
Util.track("lazy_plugins")
if not Cache.setup() then
Util.track("plugins")
if Module.changed or not State.load() then
-- rebuild state
local Plugin = require("lazy.plugin")
Module.add_module(vim.fn.stdpath("config") .. "/lua/" .. Config.options.plugins:gsub("%.", "/"))
vim.schedule(function()
vim.notify("Reloading")
end)
Util.track("plugin_normalize")
Util.track("normalize")
Plugin.normalize(require(Config.options.plugins))
if not Config.plugins.lazy then
Plugin.plugin({
@ -36,13 +52,13 @@ function M.setup(opts)
end
Util.track()
Util.track("plugin_process")
Util.track("process")
Plugin.process()
Util.track()
end
Util.track()
Util.track("lazy_install")
Util.track("install")
for _, plugin in pairs(Config.plugins) do
if not plugin.installed then
require("lazy.manager").install({
@ -53,14 +69,15 @@ function M.setup(opts)
end
Util.track()
Util.track("loader_setup")
local Loader = require("lazy.loader")
Util.track("loader")
Loader.setup()
Util.track()
Loader.init_plugins()
Util.track() -- end setup
Loader.init_plugins()
done = true
vim.cmd("do User LazyDone")
end