Speed up large selection deletes#107
Merged
krzyzanowskim merged 1 commit intokrzyzanowskim:mainfrom Mar 20, 2026
Merged
Conversation
Sampling showed deleteBackward spending most of its time materializing the deleted text for the yank ring through NSTextLayoutManager.substring(in:). For a large selection, that walks the range through TextKit substring enumeration before the actual deletion happens. Use the backing attributed string from NSTextContentStorage to read the deleted text directly by NSRange instead. This keeps yank behavior intact without paying the layout-manager substring cost on every large delete. The existing undo coverage now includes delete-then-yank so the fast path is still checked against the expected deleted text.
b7247f9 to
c948c61
Compare
Comment on lines
-44
to
+45
| updateSelectedRangeHighlight() | ||
| updateSelectedLineHighlight() | ||
| layoutGutter() | ||
| setNeedsLayoutSafe() | ||
| needsDisplay = true |
Owner
There was a problem hiding this comment.
was that intentional part of the change?
krzyzanowskim
added a commit
that referenced
this pull request
Mar 20, 2026
- Add TextKit2 viewport/layout convergence, safe relayout, and post-layout selection scroll handling - Fix viewport bounds calc, gutter offset/width issues, and ensure viewport range layout - Track speech state via AVSpeechSynthesizer delegate; validate Stop Speaking - Improve large selection delete performance (#107) - Resolve NavigationSplitView crash (#102); add ignoresSafeArea; reset typing attributes and introduce resetTypingAttributes() - Fix sizeToFit() gutter width handling (#101) - Major accessibility improvements (VoiceOver, selection, scrolling, traits, notifications) in 2.3.3 - Adjust layout fragment height handling (2.3.2) - Color/appearance and typing attribute updates (2.3.1) - Rework 2.3.0 section: consolidate features, fixes, refactors, and tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Doing select-all + delete in the Ode to STTextView in the example Text Editor was beach balling badly for a few seconds on my machine. This fix speeds it up dramatically.
Sampling showed deleteBackward spending most of its time materializing the deleted text for the yank ring through NSTextLayoutManager.substring(in:). For a large selection, that walks the range through TextKit substring enumeration before the actual deletion happens.
Use the backing attributed string from NSTextContentStorage to read the deleted text directly by NSRange instead. This keeps yank behavior intact without paying the layout-manager substring cost on every large delete.
The existing undo coverage now includes delete-then-yank so the fast path is still checked against the expected deleted text.