Skip to content

perf(rendering): eliminate O(N^2) bottleneck in fold indicator detection#1567

Merged
sinelaw merged 1 commit intomasterfrom
foldable_perf
Apr 15, 2026
Merged

perf(rendering): eliminate O(N^2) bottleneck in fold indicator detection#1567
sinelaw merged 1 commit intomasterfrom
foldable_perf

Conversation

@sinelaw
Copy link
Copy Markdown
Owner

@sinelaw sinelaw commented Apr 15, 2026

Refactor fold indicator calculation to iterate only over visible ViewLines instead of performing redundant linear scans of the entire viewport byte buffer. This fixes 100% CPU usage when thousands of lines are hidden by a collapsed fold.

  • Add source_start_byte to ViewLine for efficient mapping.
  • Refactor fold_indicators_for_viewport to use visible lines.
  • Remove redundant O(N) byte_offset_of_line_in_bytes helper.
  • Update tests and remove unused folding helper functions.

Refactor fold indicator calculation to iterate only over visible
ViewLines instead of performing redundant linear scans of the entire
viewport byte buffer. This fixes 100% CPU usage when thousands of lines
are hidden by a collapsed fold.

- Add source_start_byte to ViewLine for efficient mapping.
- Refactor fold_indicators_for_viewport to use visible lines.
- Remove redundant O(N) byte_offset_of_line_in_bytes helper.
- Update tests and remove unused folding helper functions.
@sinelaw sinelaw merged commit 53050bb into master Apr 15, 2026
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant