vim-better-whitespace icon indicating copy to clipboard operation
vim-better-whitespace copied to clipboard

Significant slowdown

Open krid78 opened this issue 7 years ago • 4 comments

Hi,

(at least) on my ARMv7-Platform I realize a significant slowdown when I enable the plugin.

I go with the default setting, and have in addition

autocmd BufWritePre * StripWhitespace
let g:better_whitespace_filetypes_blacklist=['markdown', 'unite', 'qf', 'help']

Is this problem known?

With kind regards, Daniel

krid78 avatar Mar 06 '17 20:03 krid78

Hi @krid78 ,

The autocmd execute whenever a file is saved. This means that when you save the file the cursor will take sometime before returning. So it is normal to experience slight performance issues. You may give https://github.com/mboughaba/vim-lessmess a try, I would love to get your feedback. My plugin does the heavy lifting when ViM is idle (in other words CursorHold event). Performance is one of the reason I wrote the plugin

Cheers, Mo

mboughaba avatar Nov 25 '17 18:11 mboughaba

Yeah, unfortunately this is a side effect of the way this plugin is currently stripping (and to a lesser extent highlighting) whitespace.

I have some ideas around improving out-of-the-box performance (only strip edited lines, don't highlight by default, etc), so I'm leaving this open and tagging this as both a bug and enhancement to be resolved later.

ntpeters avatar Feb 25 '18 07:02 ntpeters

(Sorry for wrongly pinging from the PR).

I've done some work on the plugin, but I don't know how to tackle performance overheads, especially for stripping whitespace (outside of disabling for large files). Even modified-lines-only stripping should not solve anything on large files, because it calls on an external diff which needs to read the whole file twice (once from disk, once from the buffer before it is written).

So I'm just going to rattle off a few thoughts off the top of my head, in case someone else is interested:

  • Can we allow the save, then asynchronously check for whitespace after the file is saved, strip whitespace and save again?

    I can't really image a better way than this, we can't do it fully asynchronously (i.e. without BufWrite*events) because we need to know when things are writing. Note that the diff-based modified-lines-only identification can't work on BufWritePost, so another way has to be used.

  • Should we make a strip-as-we-go technique, where instead of stripping on file save, at every set of changes we add whitespace stripping?

  • If the highlighting is problematic, can we highlight only the current window (line('w0'),line('w$'))?

    There is no window scroll event (see vim/vim#776) so it's hard to do (probably using a mix of CursorMoved, CursorHold). Plus vim probably only does the highlighting on the displayed part anyway, so not much to gain (especially with syntax, i.e. the soft technique).

Cimbali avatar Jan 18 '19 15:01 Cimbali

For stripping whitespace, I have written axelf4/vim-strip-trailing-whitespace which is very fast in the common case. It avoids the need to diff the file by always tracking the modified lines that end up with trailing WS.

axelf4 avatar Jan 07 '20 16:01 axelf4