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

refactor: use nvim_set_hl to speed up startup time

Open cljoly opened this issue 2 years ago • 11 comments

On my machine, prior to this change, the colorscheme adds about 8ms to the startup time of neovim. Using the newly introduced API nvim_set_hl, it’s a little under 3ms, so that’s more than a two times speedup!

Special care is taken to handle the fmt argument, as that’s the least friendly to nvim_set_hl.

This change strives to be backward compatible. Once neovim version 0.7.0 will be spread widely enough, further performance gain are within reach by:

  • removing the fallback that calls string.format
  • defining the group_settings so that those can be passed to nvim_set_hl directly

cljoly avatar May 08 '22 12:05 cljoly

Using https://github.com/rhysd/vim-startuptime with vim-startuptime -vimpath nvim, before the change on my machine I get:

  AVERAGE       MAX       MIN
------------------------------
64.994300 65.748000 64.236000: ~/.config/nvim/init.lua
 8.342700  8.888000  7.954000: ~/.local/share/nvim/site/pack/paqs/start/onedark.nvim/colors/onedark.lua

and after:

  AVERAGE       MAX       MIN
------------------------------
60.578100 62.654000 59.836000: ~/.config/nvim/init.lua
 6.268300  6.810000  5.928000: loading packages
 3.631400  3.860000  3.472000: loading rtp plugins
 2.773000  2.908000  2.604000: reading ShaDa
 2.659900  2.859000  2.508000: ~/.local/share/nvim/site/pack/paqs/start/onedark.nvim/colors/onedark.lua

cljoly avatar May 09 '22 21:05 cljoly

The latest commit will need to be squashed if this PR is merged, but in the meantime, it makes testers live easier because they can just pull from the branch.

fmt was incorrectly handled previously, specifically the iteration was incorrect in Lua. The latest commit fixes that.

cljoly avatar May 10 '22 07:05 cljoly

After daily driving this change, I have not noticed any more discrepancies compared to master.

cljoly avatar May 12 '22 19:05 cljoly

This plugin initially started with nvim_set_hl. But we switched to vim highlight to solve some color highlight issue. Let me check that once

navarasu avatar May 14 '22 06:05 navarasu

Looking at the 0.7 changelog, it seems that nvim_set_hl has been significantly improved, so hopefully that’ll work now.

cljoly avatar May 14 '22 11:05 cljoly

Sure. Let me verify it this week and will merge if no issues

navarasu avatar May 15 '22 10:05 navarasu

Cool, let me know if you need help!

cljoly avatar May 15 '22 13:05 cljoly

Did you encounter any issues in the end?

cljoly avatar Jun 04 '22 17:06 cljoly

ping @navarasu , in case the notification just got lost.

cljoly avatar Jun 18 '22 14:06 cljoly

Rebased on the most recent master branch.

cljoly avatar Oct 02 '22 14:10 cljoly

let's get this merged...

carmen-gh avatar Apr 05 '23 12:04 carmen-gh