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

Improve startup time by hard-coding the 256 color #93

Closed
wants to merge 4 commits into from
Closed

Improve startup time by hard-coding the 256 color #93

wants to merge 4 commits into from

Conversation

laggardkernel
Copy link

@laggardkernel laggardkernel commented Feb 21, 2019

vim-one converts the color hex code to 256 color code in highlight command wrapper function called <sid>X(group, fg, bg, attr). The unnecessary calculation in all of its 380+ highlight definitions makes vim-one one of the slowest vim colorschemes.

I realized this from the explanation made by @geoffharcourt at issue #74 . Someone reported the slow startup caused by vim-one in issue #84 as well.

In my experiment, I removed the conversion, hard-coded the closest 256 color code, defined a new hi wrapper for highlight definition. It turns out that this improves the startup time hugely.

At the same time, the original hi wrapper function <sid>X(group, fg, bg, attr) is kept for user customization.

vim-one loading time
Original 170.621 ms
Hard code 256 color 33.659 ms
Use hi statements directly 12.178 ms
# the original one
❯ vim-profiler.py -r 10 nvim
=====================================
Top 10 plugins slowing nvim's startup
=====================================
1       170.621   vim-one
2         6.274   vim-airline
3         4.038   vim-polyglot
4         3.496   coc.nvim
5         2.645   colorizer
6         2.413   vim-textobj-xmlattr
7         2.313   vim-textobj-comment
8         1.795   vim-sensible
9         1.664   vim-textobj-line
10        1.341   ctrlp.vim
=====================================

# hard-code the 256 color
vim-one  new-hi-wrapper
❯ vim-profiler.py -r 10 nvim
=====================================
Top 10 plugins slowing nvim's startup
=====================================
1        33.659   vim-one
2         6.735   vim-airline
3         4.161   vim-polyglot
4         3.652   coc.nvim
5         2.729   colorizer
6         2.443   vim-textobj-xmlattr
7         2.440   vim-textobj-comment
8         1.753   vim-textobj-line
9         1.749   vim-sensible
10        1.495   ctrlp.vim
=====================================

# using `hi` command directly
vim-one  master [⇡]
❯ vim-profiler.py -r 10 nvim
=====================================
Top 10 plugins slowing nvim's startup
=====================================
1        12.178   vim-one
2         6.434   vim-airline
3         3.923   vim-polyglot
4         3.519   coc.nvim
5         2.720   colorizer
6         2.542   vim-textobj-comment
7         2.391   vim-textobj-xmlattr
8         1.797   vim-textobj-line
9         1.724   vim-sensible
10        1.363   ctrlp.vim
=====================================

The final result 34 ms is acceptable, considering vim-one uses so many highlight definitions.

Credit

  • The new highlight (:help hi) command wrapper is borrowed from Vim theme oceanic-next.

@geoffharcourt
Copy link
Contributor

This is an awesome compromise between the flexible original approach and your idea in #74 that retains the ongoing maintainability of the current repo. Nice!

@rakr
Copy link
Owner

rakr commented Apr 9, 2019

Thanks a lot for your contribution and sorry this has been taken into account so late, life has been pretty busy and I must admit that I did not spend much time on this repo.
As there was a merge conflict with other pull request I merged the code manually.

@rakr rakr closed this Apr 9, 2019
@kevinhwang91
Copy link

@laggardkernel IncSearch doesn't work properly.

Fixed by

-  hi! link IncSearch OneHue6
+  call <sid>X('IncSearch',    s:hue_6,         '',               '')

laggardkernel added a commit to laggardkernel/vim-one that referenced this pull request Apr 21, 2021
`hi! link` overrides another `hi link` but not a `hi` def. Cause
some defs may defined by default, use `hi` to override them.

`hi` def all the builtin groups may be a much safer way.
Check `:h highlight-groups` or `:highlight-default`.

rakr#93 (comment)
laggardkernel added a commit to laggardkernel/vim-one that referenced this pull request Apr 21, 2021
- `hi clear` loads default groups but `hi clear IncSearch` not
- `hi` inherits existing group and override it, while `hi! link`
  existing groups

rakr#93 (comment)
@laggardkernel
Copy link
Author

@kevinhwang91 Sorry, haven't used vim for a long time. After some reading, I found the cause

  • hi {group_name} inherits existing group and override it, while hi! link
    ignore existing group definition and use only its own colors

Only a quick fix removing problematic hi! link. Maybe we should drop hi! link on the default groups (listed in :highlight-default).

hi clear

hi clear clears user defined highlight groups and load some default groups,

IncSearch      xxx term=reverse cterm=reverse gui=revers

hi! link

hi! link IncSearch OneHue6

check :hi IncSearch

IncSearch      xxx cterm=reverse gui=reverse 
                   links to OneHue6

The default def is ignored, only linked group is used, so the text (foreground) is OneHue6.

hi

If we use call <sid>X('IncSearch', s:hue_6, '', '')

IncSearch      xxx cterm=reverse ctermfg=94 gui=reverse guifg=#986801

Group def is merged with the default one, the background color is OneHue6.

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.

4 participants