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

Significant slowdown #61

Open
krid78 opened this issue Mar 6, 2017 · 4 comments
Open

Significant slowdown #61

krid78 opened this issue Mar 6, 2017 · 4 comments

Comments

@krid78
Copy link

krid78 commented Mar 6, 2017

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

@mboughaba
Copy link

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

@ntpeters
Copy link
Owner

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.

@Cimbali Cimbali mentioned this issue Jan 18, 2019
@Cimbali
Copy link
Collaborator

Cimbali commented Jan 18, 2019

(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 Highlighting matching parenthese doesn't work after scrolling viewport 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).

@axelf4
Copy link

axelf4 commented Jan 7, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants