cpow / neovim-for-newbs

a simple lua neovim configuration for newbs
452 stars 81 forks source link

Major performance improvements, made lazy loading false by default #5

Open Selyss opened 6 months ago

Selyss commented 6 months ago

By using the lazy package manager's built in features, I have improved the start-up time from ~200ms to ~17ms (on my machine). This was achieved by loading plugins either lazily or by tweaking the plugin load order. The changes are commented and explained in the code, but just to explain briefly:

The cmd option only loads a plugin when a certain command is entered, not on start-up.

The event option only loads plugins when certain events in neovim's event loop are triggered.

The keys option allows you to set keymaps that actually load the plugin itself. For example, telescope is not loaded until the user executes a telescope key command. The end user doesn't notice this, and not loading a major plugin largely improves performance.

The only other change made was to make lazy loading off by default. In the config, I noticed a lot of lazy = false. Lazy has an option to specify the default state of lazy loading, which I have switched off by default in the init.lua. No longer do you need to specify when lazy loading should be false, only when it's true.

I have documented all options with comments, in hopes that anyone with the config can easily understand or have a point of reference if they are wondering what the line of code does. If anyone has any questions about these changes, feel free to let me know.👍

KisNJ commented 4 months ago

When i have mason cmd="Mason" set Spawning language server with cmd: table: 0x7077f887dc90 failed. The language server is either not installed, missing from PATH, or not executable. removing cmd resolves the issue

Selyss commented 4 months ago

@KisNJ I don't believe that would cause the issue. The issue may be caused by another plugin that depends on mason being lazy loaded.

That specific lazy load option for mason is used in folke's neovim configuration LazyVim and many other configurations. Please link your configuration so I can look into that more. If you're able to reproduce the error without any other plugins that would affect the startup, let me know.

GNOMES commented 3 months ago

Tried making your suggested changes to Telescope, and found that the keys mapped your way did not always load Telescope reliably for all Telescope builtins I had mapped.

I found this more reliable:

keys = {
        {
            "<leader>gc",
            function()
                require("telescope.builtin").git_commits()
            end,
            desc = "Telescope [g]it_[c]ommits",
        },
        {
            "<leader>ff",
            function()
                require("telescope.builtin").find_files()
            end,
            desc = "Telescope [f]ind_[f]iles",
        },
},
Selyss commented 3 months ago

Tried making your suggested changes to Telescope, and found that the keys mapped your way did not always load Telescope reliably for all Telescope builtins I had mapped.

I found this more reliable:

keys = {
      {
          "<leader>gc",
          function()
              require("telescope.builtin").git_commits()
          end,
          desc = "Telescope [g]it_[c]ommits",
      },
      {
          "<leader>ff",
          function()
              require("telescope.builtin").find_files()
          end,
          desc = "Telescope [f]ind_[f]iles",
      },
},

Oh that's my bad, I may change that in my pr. Are there any specific cases where it was unreliable?

GNOMES commented 3 months ago

I take my statement back, it seems I may have had conflicting bindings. Your formatting works for me on fresh config.

Not sure if there are benefits to either your method or mine.