Repository navigation
perf(editor): answer attributedString() with the text storage - #4562
Merged
Merged
Conversation
The input system's attributedString() copied every character and attribute run of the document, 41 ms and 5.7 MB at 1.9M characters. It now returns the storage, as NSTextView does. The other reads the issue lists are not copies: bridging the storage's NSBigMutableString to a String shares its buffer and copies one block when the next edit touches it, about 2 us. Length-only reads on the keystroke path read textStorage.length, and the band checks its size limit first. A test pins that the bridged read neither copies the document nor changes after a later edit, which the fold pass and the binding rely on.
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.
Summary
NSTextInputClient.attributedString()returns the text storage itself, asNSTextViewdoes, instead of an attributed substring of the whole document.textStorage.length: the run controls' refresh, the statement band (its size guard now runs before the text is read), the pending-caret hand-off, diagnostics and the inline suggestion check.Stringis not a copy of the document:NSBigMutableStringshares its buffer and copies one block when the next edit touches it. The fold pass, the binding writeback and the scans keep that snapshot, which they rely on to stay unchanged while the editor goes on editing. A liveNSMutableStringaccessor would give that up and save nothing.Measured with a 1.9M-character storage with token-level attribute runs, typing at the end, the read held across the edit (
swiftc -Oprobe, 50 keys):attributedString()textStorage.stringheld across an edittextStorage.mutableStringSo the per-key copies the issue lists cost microseconds each, and the only whole-document copy among them was
attributedString().Test plan
TextStorageReadTests(TableProTextEngineTests):attributedString()is the storage (fails on main); readingTextView.stringon a 4M-unit document and editing after it grows the heap by under 2 MB, where a copy is 8 MB; the read stays a snapshot after a later edit.verify.sh package TableProEditorover the input, marked text, IME and text view suites: 38 passed.verify.sh test StatementRunControllerTests QueryDiagnosticsRefreshTests InlineSuggestionManagerFocusTests SQLEditorPendingTextTestsfor the app-side length reads: 42 passed.Closes #4533