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

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

laggardkernel
Copy link

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

`hi link` reduces loading time from 33.6 ms to 18.3 ms.

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

rakr commented Apr 30, 2019

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
Copy link
Author

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.

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

Successfully merging this pull request may close these issues.

2 participants