Apply all folds in one update #10

Merged
marijn merged 2 commits from andreimokrousov/language:bulkfoldupdate into main 2026-06-22 21:39:38 +02:00
Contributor

This PR deals with one problem - transactions with a large number of foldEffects are very slow (For example, folding all foldable ranges of 10MB json (~130K ranges) takes about 10-15s on my machine; in contrast, unfolding them all takes only 1-2s)

I believe that the root of the problem is updating ranges one-by-one in this line folded.update({add: [widget.range(e.value.from, e.value.to)]}), because every call re-creates RangeBuilder and iterates through every existing fold, effectively making such transaction quadratic by foldEffect count.

In this PR I group all ranges that should be folded, and apply them all at once.
This reduces the time from 10-15s to <1s in my case.

Please take a look at this patch and kindly tell if it can be merged. Thanks!

This PR deals with one problem - transactions with a large number of `foldEffect`s are very slow (For example, folding all foldable ranges of 10MB json (~130K ranges) takes about 10-15s on my machine; in contrast, unfolding them all takes only 1-2s) I believe that the root of the problem is updating ranges one-by-one in this line `folded.update({add: [widget.range(e.value.from, e.value.to)]})`, because every call re-creates RangeBuilder and iterates through every existing fold, effectively making such transaction quadratic by foldEffect count. In this PR I group all ranges that should be folded, and apply them all at once. This reduces the time from 10-15s to <1s in my case. Please take a look at this patch and kindly tell if it can be merged. Thanks!
andreimokrousov changed title from WIP: apply all folds in one update to apply all folds in one update 2026-06-22 18:21:23 +02:00
andreimokrousov changed title from apply all folds in one update to Apply all folds in one update 2026-06-22 18:21:44 +02:00
Owner

Oh right, yes, that would be quadratic. Having that many folds come in at the same time wasn't something I considered. The patch looks good, but could you make sure the indentation of the if at the bottom uses two instead of four spaces?

Oh right, yes, that would be quadratic. Having that many folds come in at the same time wasn't something I considered. The patch looks good, but could you make sure the indentation of the if at the bottom uses two instead of four spaces?
Author
Contributor

Oops, vscode formatter glitched.
I fixed it, thanks!

Oops, vscode formatter glitched. I fixed it, thanks!
marijn merged commit 487593a321 into main 2026-06-22 21:39:38 +02:00
marijn referenced this pull request from a commit 2026-06-22 21:39:39 +02:00
Owner

Thanks!

Thanks!
Author
Contributor

Sorry for writing into a closed PR. Could you share your plans on releasing a new version of this extension, please?

Sorry for writing into a closed PR. Could you share your plans on releasing a new version of this extension, please?
Owner

I've tagged a version 6.12.4. Don't worry about commenting in closed PRs.

I've tagged a version 6.12.4. Don't worry about commenting in closed PRs.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/language!10
No description provided.