LucHermitte / VimFold4C

Vim folding ftplugin for C & C++ (and similar langages)
37 stars 6 forks source link

How to fix slowness #15

Open allopislozano opened 5 years ago

allopislozano commented 5 years ago

Hi,

The plugin is a bit slow sometimes when reading big cpp files (>2000 lines). Is there any way to work around this issue? Any kind of caching or disabling the plugin altogether for specific files or files above a certain number of lines?

Thanks

LucHermitte commented 5 years ago

Hi,

It isn't implemented, but it should be easy to add. What about an option like the following?

(bpg):fold_options.fallback_method = { 'line_threshold': 2000, 'method' : 'indent' }

If you think of a better name, don't hesitate.

allopislozano commented 5 years ago

I think it is a nice practical idea if the speed issue is not easily solvable (which would be the ideal solution), and the name is great. Another idea would be to implement some kind of caching, looks like the folding is calculated every time the buffer is shown, even if it was already opened before and hasn't changed (for example when switching from header to cpp file, which is quite common)

LucHermitte commented 5 years ago

Actually a caching is already in place, still it doesn't solve all performance issues. I guess I'll eventually need to rewrite everything in another language (like Python) to improve the performances of C and C++ folding.

Switching back and forth shouldn't be much of an issue, IIRC -- I always keep the buffers opened side by side in two different windows. I'll need to see whether reopening a buffer in a new window triggers the clear event.

LucHermitte commented 5 years ago

Note: There is indeed a cache, but it's a cache of the lines already analyzed (regarding the context they belong to), not a cache of the result previously returned for the current line.

IOW: I need a timestamped cache to know when things need to be recomputed.

AngelDev06 commented 1 month ago

Yeah sadly this is too slow to be usable and I believe the culprit is the foldmethod used.

LucHermitte commented 1 month ago

I definitely don't have the time to do it. May be rewriting it in Vim script 2 (from Vim9) could speed up things enough for the plugin to be usable.

I don't know if we could work without a cache though. Indeed, current implementation of fold level (on vim side), is kind-of recursive :(

AngelDev06 commented 1 month ago

I mentioned this because in the docs it's said that the expression is evaluated for every single line so maybe this is what's causing the slowness.

Do you think it would be possible to use manual as a foldmethod? (if you have the time of course)

LucHermitte commented 1 month ago

"manual" is not really on my side. It's directly handled by Vim, and it would be up to you (/us) to define each and every fold. Ho!? Unless you mean using the plugin once in a while to found and define folds "manually". 🤔

Many people are fine with syntax or indent. I tried to do something a bit more pretty with my plugin. Another alternative would be to rely on a LSP client. It seems really fast, but I prefer where I put folders, and "my" replacement text...