rktjmp / hotpot.nvim

:stew: Carl Weathers #1 Neovim Plugin.
MIT License
361 stars 10 forks source link

How to reduce startup time besides using `vim.loader.enable()`? #125

Open rktjmp opened 11 months ago

rktjmp commented 11 months ago

Discussed in https://github.com/rktjmp/hotpot.nvim/discussions/116

Originally posted by **s-cerevisiae** September 3, 2023 v0.9.0 did fix the path separator problem on Windows. However during testing I found that the startup time (from v0.8 on) is ~2x slower than v0.7.0 and I think that's due to recent versions removing the byte code cache. I added `vim.loader.enable()` to the first line of my bootstrapping lua file but that made little (~10ms) difference. This happens to me on both Linux and Windows machines so there might be something wrong with my config. I'd like to know the currently recommended way to use `hotpot.nvim` with `lazy.nvim`. Thank you in advance.
My current (rather convoluted) init.lua with lazy.nvim and hotpot.nvim ```lua vim.loader.enable() local function bootstrap(plugin) local _, name = unpack(vim.split(plugin, '/')) local plugin_path = vim.fn.stdpath('data')..'/lazy/'..name if not vim.loop.fs_stat(plugin_path) then vim.notify('Installing '..plugin..' to '..plugin_path, vim.log.levels.INFO) vim.fn.system({ 'git', 'clone', '--filter=blob:none', '--single-branch', 'https://github.com/'..plugin, plugin_path, }) end vim.opt.runtimepath:prepend(plugin_path) end bootstrap('folke/lazy.nvim') bootstrap('rktjmp/hotpot.nvim') require('hotpot').setup({ provide_require_fennel = true, -- BTW `:StartupTime` shows that `hotpot.fennel` takes up ~70ms even this is not set -- only happens on >0.8.0 }) local plugins = { { 'rktjmp/hotpot.nvim' }, } local plugin_def_path = vim.fn.stdpath('config')..'/fnl/config/plugins' if vim.loop.fs_stat(plugin_def_path) then for file in vim.fs.dir(plugin_def_path) do local name = file:match("^(.*)%.fnl$") plugins[#plugins + 1] = require("config.plugins."..name) end end require('lazy').setup(plugins) require('config') ```
rktjmp commented 11 months ago

@monkoose, not sure if you are still using hotpot, do you have a particularly large amount of complex macros?

Looking at this line, we have to clear the in-memory versions of macros each time we build and can be expensive to code-gen.

https://github.com/rktjmp/hotpot.nvim/blob/bedc290557817b0ebf97d2b389bc5bb596a25bd7/fnl/hotpot/api/make.fnl#L83-L90

monkoose commented 11 months ago

I do use it, but I have converted it to use .hotpot.lua only and compile on demand, and compile into /lua directory and not use any cache files. It requires some workaround in init.lua, but after that it works like a charm, doesn't preload hotpot on neovim startup and compiles when any fennel file in my config was changed.

And maybe it was some macro issue, because previously I have used vim.api functions in some of my macros and with such option to make it work like that

    compiler = {
        macros = {
            env = "_COMPILER",
            compilerEnv = _G,
            allowedGlobals = false,
        },
    },

But after I have realized that this is wrong approach and it messes up with other fennel compilers (from aniseed or fennel-ls) I have fixed it, but I have already switched to using hotpot only on demand, so can't be sure that it was the issue.

My init.lua looks like this (there is workaround to make neovim work on first startup, when there are missing compiled files)

vim.loader.enable()

local plugins_path = vim.fn.stdpath("data") .. "/lazy"
local config_path = vim.fn.stdpath("config")

-- Bootstrap lazy.nvim
local lazy_path = plugins_path .. "/lazy.nvim"
if not vim.loop.fs_stat(lazy_path) then
  vim.notify("Fetching lazy.nvim...", vim.log.levels.INFO)
  vim.fn.system({
    "git",
    "clone",
    "--depth=1",
    "--filter=blob:none",
    "--single-branch",
    -- "--branch=stable", -- latest stable release
    "https://github.com/folke/lazy.nvim.git",
    lazy_path,
  })
end

vim.opt.runtimepath:prepend(lazy_path)

local ok, plugins = pcall(require, "plugins.lazy")
if not ok then
  vim.print(plugins)
  plugins = {
    {
      "rktjmp/hotpot.nvim",
      dependencies = "monkoose/parsley",
      config = function() require("hotpot.api.make").auto.build(config_path) end,
    },
  }
end

require("lazy").setup({
  performance = {
    rtp = {
      disabled_plugins = {
        "gzip",
        "tarPlugin",
        "zipPlugin",
        "matchparen",
        "tutor",
        "matchit",
        "tohtml",
        "rplugin",
      },
    },
  },
  ui = { border = {'┏', '━', '┓', '┃', '┛', '━',  '┗', '┃'} },
  spec = plugins,
})

require("conf.options")
require("statusline")
require("conf.autocmds")
require("conf.maps")

.hotpot.lua

return {
    compiler = {
        macros = {
            env = "_COMPILER",
            compilerEnv = _G,
        },
    },
    build = {
        {atomic = true},
        {"fnl/**/*macros.fnl", false},
        {"fnl/**/*.fnl", true},
        {"colors/*.fnl", true},
        {"after/**/*.fnl", true},
    },
    clean = {
      {"lua/**/*.lua", true}
    }
}