-
Notifications
You must be signed in to change notification settings - Fork 81
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
Use CursorHold instead of Cursor Moved (performance) #126
base: master
Are you sure you want to change the base?
Conversation
6895de0
to
e8920fc
Compare
Thank you for the patch. This too, I’m afraid, I won’t be taking… 😐 The plugin used to use What size is your Vim window? What machine are you on? |
It makes a huge difference on my machine regarding startup time (I've tested this on macOS Catalina and Ubuntu 18.04, both with Using diff move.txt hold.txt | grep vim-css
< 153.673 002.377 002.377: sourcing ~/.config/nvim/bundle/vim-css-color/autoload/css_color.vim
< 1891.508 000.814 000.814: sourcing ~/.config/nvim/bundle/vim-css-color/syntax/colornames/basic.vim
< 1894.072 004.576 003.762: sourcing ~/.config/nvim/bundle/vim-css-color/syntax/colornames/extended.vim
< 1894.431 1743.615 1736.661: sourcing ~/.config/nvim/bundle/vim-css-color/after/syntax/css.vim
> 088.510 001.061 001.061: sourcing ~/.config/nvim/bundle/vim-css-color/autoload/css_color.vim
> 089.201 000.318 000.318: sourcing ~/.config/nvim/bundle/vim-css-color/syntax/colornames/basic.vim
> 090.807 002.051 001.733: sourcing ~/.config/nvim/bundle/vim-css-color/syntax/colornames/extended.vim
> 091.068 003.743 000.631: sourcing ~/.config/nvim/bundle/vim-css-color/after/syntax/css.vim Using this bench fix (tried just calculating in all 864.848 # CursorMoved
5.982 # CursorHold I get your problem with hiding vs. fixing - at least for me the seconds long startup time felt unbearable, and I preferred the Edit: My vim window size is ~130x70 colums/lines. |
Yeah, obviously. It’s very weird that
I.e. effectively instant startup. Certainly nothing like what you are seeing… Thing is, I am using regular Vim 8.1 (on Mac). So… is NeoVim doing something really silly? |
It's a little better with vim 8.1 - but still factor 10 slower: diff move.txt hold.txt | grep vim-css
< 075.024 001.508 001.508: sourcing ~/.config/nvim/bundle/vim-css-color/autoload/css_color.vim
< 852.235 000.129 000.129: sourcing ~/.config/nvim/bundle/vim-css-color/syntax/colornames/basic.vim
< 853.153 001.194 001.065: sourcing ~/.config/nvim/bundle/vim-css-color/syntax/colornames/extended.vim
< 853.316 779.958 777.256: sourcing ~/.config/nvim/bundle/vim-css-color/after/syntax/css.vim
> 082.854 001.904 001.904: sourcing ~/.config/nvim/bundle/vim-css-color/autoload/css_color.vim
> 083.737 000.205 000.205: sourcing ~/.config/nvim/bundle/vim-css-color/syntax/colornames/basic.vim
> 086.239 002.909 002.704: sourcing ~/.config/nvim/bundle/vim-css-color/syntax/colornames/extended.vim
> 086.515 005.791 000.978: sourcing ~/.config/nvim/bundle/vim-css-color/after/syntax/css.vim Maybe it's some weird cross-issue with another plugin, I'll investigate that. |
Found something: This is dependent on the option diff move.txt hold.txt | grep vim-css
< 085.125 001.085 001.085: sourcing ~/.config/nvim/bundle/vim-css-color/autoload/css_color.vim
< 086.513 000.154 000.154: sourcing ~/.config/nvim/bundle/vim-css-color/syntax/colornames/basic.vim
< 087.865 001.630 001.476: sourcing ~/.config/nvim/bundle/vim-css-color/syntax/colornames/extended.vim
< 088.069 004.161 001.446: sourcing ~/.config/nvim/bundle/vim-css-color/after/syntax/css.vim
> 083.431 001.043 001.043: sourcing ~/.config/nvim/bundle/vim-css-color/autoload/css_color.vim
> 084.026 000.231 000.231: sourcing ~/.config/nvim/bundle/vim-css-color/syntax/colornames/basic.vim
> 085.532 001.862 001.632: sourcing ~/.config/nvim/bundle/vim-css-color/syntax/colornames/extended.vim
> 085.732 003.473 000.567: sourcing ~/.config/nvim/bundle/vim-css-color/after/syntax/css.vim |
Oooh, yeah. That makes a giant difference for me as well. And I can now also see that if your view of the file has almost everything folded away most of the time, then you wouldn’t care about the lagginess of using I want to see if it’s possible to fix this properly, though. It should be. So. The first obvious issue is that when I open So this patch limits parsing to only unfolded lines: diff --git i/autoload/css_color.vim w/autoload/css_color.vim
index f72d598352b..0cb673b9d48 100644
--- i/autoload/css_color.vim
+++ w/autoload/css_color.vim
@@ -224,7 +224,7 @@ function! s:parse_screen()
let b:css_color_upd = upd
let left = max([ wv.leftcol - 15, 0 ])
let width = &columns * 4
- call filter( range( line('w0'), line('w$') ), 'substitute( strpart( getline(v:val), col([v:val, left]), width ), b:css_color_pat, ''\=s:create_syn_match()'', ''g'' )' )
+ call filter( range( line('w0'), line('w$') ), '( 0 > foldclosed(v:val) ) && substitute( strpart( getline(v:val), col([v:val, left]), width ), b:css_color_pat, ''\=s:create_syn_match()'', ''g'' )' )
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" This change alone makes a huge difference while scrolling around the file initially. So that’s good. However, it doesn’t change the startup delay at all. It’s also still moderately painful to open a fold which contains a so far unparsed color. Adding new syntax highlights under For now I next want to investigate whether it’s possible to somehow postpone the installation of the autocommands until after the file has finished opening. Theoretically that should at least solve the startup time issue… |
Thanks for digging into this! I'm actually not really using Applying your patch actually increases the startup delay for me:
I'm going to just deactivate Let me know if I can test more things to help out! |
Is that a tenfold increase…!?
It’s not. I don’t know whether it’s possible to make make it perform acceptably, with robust code – but if possible then I want to make it so. And I just saw that Vim 8 does have a I’m a weirdo who doesn’t like telling users they have to live on the bleeding edge just to make my own life easier, so I’d also want to structure the plugin such that it can be async and smooth on Vim 8 but continues to work synchronously and no worse than before on Vim 7. (Not least because that’s also necessary to support Vim 8 versions compiled without timer support.) |
Seems like it. I was using Really apprechiating your effords here to fix this and also keep backwards compatibility. Good luck! Let me know if I can test something out, I'd be glad to help! |
I've noticed massive performance issues when using
CursorMoved
, fixed it for me by switching toCursorHold
.