[vim/vim] cache foldexpr levels (Issue #16184)

11 views
Skip to first unread message

Enno

unread,
Dec 7, 2024, 2:30:33 AM12/7/24
to vim/vim, Subscribed

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.


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/16184@github.com>

Enno

unread,
Dec 15, 2024, 2:27:32 AM12/15/24
to vim/vim, Subscribed

As the discussion lervag/vimtex#3054 showed, Vim already does so if the &foldexpr accounts for it. So it's rather a matter of documenting than rewriting it.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/16184/2543517066@github.com>

Enno

unread,
Dec 15, 2024, 2:27:38 AM12/15/24
to vim/vim, Subscribed

Closed #16184 as completed.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/16184/issue_event/15659504239@github.com>

Reply all
Reply to author
Forward
0 new messages