onedarkpro.nvim icon indicating copy to clipboard operation
onedarkpro.nvim copied to clipboard

Improve startup time by compiling user customizations and computed values

Open mrjones2014 opened this issue 3 years ago • 2 comments

Lots of color schemes do something like this: https://github.com/EdenEast/nightfox.nvim/blob/main/lua/nightfox/lib/compile.lua

It can improve startup time by quite a bit. I love onedarkpro.nvim but according to :PackerProfile it’s one of the plugins that takes the longest to source on startup.

I can work on a PR for this probably tomorrow and early next week.

mrjones2014 avatar Aug 27 '22 14:08 mrjones2014

This is absolutely on the roadmap. The rewrite was done with these types of features in mind. I've half baked something which I'll merge in the next week. Need to decide how I'll get filetype highlights working with it too.

olimorris avatar Aug 27 '22 15:08 olimorris

Oh awesome, glad to hear you’ve got something in the works. Let me know if there’s any way I can help

mrjones2014 avatar Aug 27 '22 20:08 mrjones2014

@mrjones2014 - Would love to get your feedback on startup times after 565f7b463640412825a066bc7d20db4f5c352b56!

olimorris avatar Oct 03 '22 19:10 olimorris

Nice, funny enough I was just looking at this issue about an hour ago 🤣

I’ll take a look shortly

mrjones2014 avatar Oct 03 '22 19:10 mrjones2014

It seems to take pretty much the same time for me.

mrjones2014 avatar Oct 03 '22 20:10 mrjones2014

Around 6ms.

mrjones2014 avatar Oct 03 '22 20:10 mrjones2014

fluctuates between 5-9ms

mrjones2014 avatar Oct 03 '22 20:10 mrjones2014

Well that just sucks 😆. Using PackerCompile?

Using vim-startuptime I see 0.74ms with caching and 3.61ms without.

olimorris avatar Oct 03 '22 20:10 olimorris

Also takes it down to 64th place in overall load times down from 13th

olimorris avatar Oct 03 '22 20:10 olimorris

I might be doing something wrong, unsure. Do you see anything in my config that stands out?

https://github.com/mrjones2014/dotfiles/blob/master/.config/nvim/lua/my/configure/theme.lua

mrjones2014 avatar Oct 03 '22 20:10 mrjones2014

It all looks okay. You're loading all of the plugins which will add a tonne of weight and if you've got custom Telescope highlight groups you may want to set telescope = false in the plugins section.

I wonder if the so called "improvement" on my side is due to my measuring tool of choice.

There should definitely be an improvement though as we're not parsing all of the highlight groups for all of the editor, syntax and plugins; injecting colors and styles. That's probably about 500 highlight groups that we're avoiding.

olimorris avatar Oct 03 '22 21:10 olimorris

I'll try enabling only the plugins I'm using and see if that helps.

mrjones2014 avatar Oct 03 '22 21:10 mrjones2014

Hmm, it still has about the same startup time for me.

mrjones2014 avatar Oct 03 '22 21:10 mrjones2014

So I happened to find and manually run the :OnedarkproCache command and it shaved about 70% off the startup time.

Any idea why caching = true in my config wouldn't be doing that automatically?

mrjones2014 avatar Oct 04 '22 13:10 mrjones2014

So I happened to find and manually run the :OnedarkproCache command and it shaved about 70% off the startup time.

Any idea why caching = true in my config wouldn't be doing that automatically?

This was a bit confusing to me too--wasn't sure if the cache would be automatically created or not when caching is set to true (and hence if the provided commands would be required or just utilities) until I found the little note about auto commands in the README.

mmirus avatar Oct 04 '22 13:10 mmirus

little note about auto commands in the README.

Ah, I didn't see this before.

I'd recommend actually changing it from a ColorScheme autocmd to a User PackerCompileDone autocmd, that way you only recompile the cache when you :PackerCompile, not every time you set the colorscheme.

mrjones2014 avatar Oct 04 '22 13:10 mrjones2014

This is great feedback. I've just pushed a change which detects if caching = true and if no cache file exists. It will then automatically generate a cache for the user. Please let me know if that works for you guys

olimorris avatar Oct 04 '22 14:10 olimorris

That seems to work, but won't recompile on changes, right? For that you'd still need an autocmd.

I'd recommend updating the bit in the README.md to recommend autocmding on User PackerCompileDone if using packer, rather than ColorScheme since that will pretty much run every time you open Neovim I think.

mrjones2014 avatar Oct 04 '22 14:10 mrjones2014

Also, my onedarkpro.nvim startup time is sub-2ms now 🎉

mrjones2014 avatar Oct 04 '22 14:10 mrjones2014

This is great to hear! I'll update the readme later. If you guys have some autocommands to share for how you're regenerating the cache, would love to see them.

olimorris avatar Oct 04 '22 14:10 olimorris

using legendary.nvim to bind my autocmds, I have an autocmd table like this:

{
  -- recompile OneDarkPro.nvim cache on :PackerCompile
  name = 'RecompileOnedarkproCache',
  {
    'User',
    ':OnedarkproCache',
    opts = {
      pattern = 'PackerCompileDone',
    },
  },
}

Or in vanilla Neovim APIs:

vim.api.nvim_create_autocmd('User', {
  command = 'OnedarkproCache',
  pattern = 'PackerCompileDone',
  group = vim.api.nvim_create_augroup('OnedarkproCacheOnPackerCompile', { clear = true })
})

mrjones2014 avatar Oct 04 '22 14:10 mrjones2014