Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rktjmp opened this issue Dec 24, 2023 Discussed in #116 · 2 comments
Open

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

rktjmp opened this issue Dec 24, 2023 Discussed in #116 · 2 comments

Comments

@rktjmp
Copy link
Owner

rktjmp commented Dec 24, 2023

Discussed in #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
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
Copy link
Owner Author

rktjmp commented Dec 24, 2023

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

;; Issue https://github.com/rktjmp/hotpot.nvim/issues/117
;; Macro modules are retained in memory, so even if they're edited,
;; we compile with the older version and output incorrect code.
;; For now (?) we will force all macros to be reloaded each time make is
;; called to ensure they're reloaded.
(case package.loaded
{:hotpot.fennel fennel} (each [k _ (pairs fennel.macro-loaded)]
(tset fennel.macro-loaded k nil)))

@monkoose
Copy link

monkoose commented Dec 24, 2023

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

rofrol referenced this issue in datwaft/nvim.conf Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants