rakr / vim-one

Adaptation of one-light and one-dark colorschemes for Vim
MIT License
2k stars 197 forks source link

Optimize loading time by reusing hi definitions with hi link #95

Open laggardkernel opened 5 years ago

laggardkernel commented 5 years ago

hi link reduces loading time from 33.6 ms to 18.3 ms. This idea is borrowed from vim theme gruvbox.

Force link hi! link is needed to override default settings, otherwise warning messages will be popped up during theme loading.

vim-one  predefined-groups
❯ vim-profiler -r 10 nvim
# omitted
=====================================
Top 10 plugins slowing nvim's startup
=====================================
1        18.253   vim-one
2         6.301   vim-airline
3         6.112   coc.nvim
4         3.811   vim-polyglot
5         2.738   colorizer
6         2.405   vim-textobj-comment
7         2.358   vim-textobj-xmlattr
8         1.691   vim-sensible
9         1.691   vim-textobj-line
10        1.285   ctrlp.vim
=====================================
rakr commented 5 years ago

Thanks for this PR, although I'd like to open a discussion on this one. Even though hi link is faster (don't know exactly why), it has a side effect that persists the color if the user changes to another theme and if this theme does not override the setting. In my mind that would make this colorscheme not a very good Vim citizen, what are your thoughts? Is it worth saving 15ms?

laggardkernel commented 5 years ago

hi link is faster because it avoids calling the custom X function to define highlight, saves the time cost on call <sid>X. After some reading on :h hi, I can confirm you're right about the side effect, hi clear doesn't clear the hi links.

Before you mentioned the side effect, I am not aware of it. In fact, I always use the vim-one light theme and don't have a workflow of switching to another colorscheme at all. After skimming the codes in Gruvbox, it turns out the maintainers of gruvbox don't realize the problem neither. Or they just ignored it.

But, you're right. Saving 15ms is not a big thing, at least in case there's an SSD on your machine. Using the hi link or not is totally okay with me. I'd like to know how others think about it.