-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
Is your feature request about something that is currently impossible or hard to do? Please describe the problem.
As observed here #16151 expression folding is slow and since Vim uses a single core likely will remain so. The &foldexpr
function is called for every line, and likely was once intended for folds whose level could be read off from the line itself (say indents, for example in mails) and not depend on its level in the syntax tree of the whole buffer.
Describe the solution you'd like
In the PR #16151 slowness was worked around by caching the fold level of each line until the buffer changes.
This way that the fold levels of all lines are only recomputed once when the buffer changes, instead of each line recomputing all fold levels independently over and over (which they have to since it depends on the whole syntax tree of the buffer).
This solution is generic, and Vim should cache these values itself until buffer changes, instead of calling &foldexpr
for each line.
Describe alternatives you've considered
The worse alternative would be to beg all authors of &foldexpr
in runtime to add a cache of foldlevels in their &foldexpr
, but this can wait, is slower and less robust.
Additional context
@Shougo proposed a fix to similar ends for syntax folds;
Fastfold can postpone recomputes till buffer changes, but they would still have to be recomputed for all lines and then cause delay.