You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.
Ideally, we fix this through converting to TextKit2 in #214.
The document doesn't have to be that large. Just medium.
Learnings from troubleshooting:
We're parsing twice. Once in textStorage delegate, and once in setEditor, for link search. That's two passes for each parse, so 4x passes. Too many.
Yet, disabling all parsing does not improve performance.
Removing the attribute application in the textStorage delegate does not improve perf. (Removes one parsing pass).
Removing the link-finding code does not improve perf. (Removes one parsing pass).
Removing both makes no difference.
Disabling all logging does not improve performance.
Rendering document-level styles once at init does not improve performance.
Replacing Range -> NSRange code did not improve performance
Retaining parsing, but disabling inline parsing within blocks (second pass) puzzlingly seems to improve performance a tiny bit, but this is probably an illusion? Either way, it's sufficiently bad that it doesn't solve anything.
Applying only font attributes and not parsing anything does not improve performance.
Passing NSTextStorage instead of NSMutableAttributedString does not improve performance (Some had reported this as a workaround, but it seems to make no difference. See Typing is slow in big documents #310 (comment))
Hypothesis:
Parsing is not the bottleneck
Rather the bottleneck seems to be text rendering. TextKit1 is a top-to-bottom text renderer.
The size of the text that needs to be laid out might matter. When text is small, more flow happens onscreen. This seems to affect perf somewhat.
... or possibly NSString -> String conversion?
Possible solutions:
Would like to replace this with TextKit2, but this won't be available until iOS16
The text was updated successfully, but these errors were encountered:
However, the textview performed terribly when I pasted in a lot of text (I used the full script of “A Streetcar Named Desire”, which is a couple thousand lines). It was not my syntax rules that were the problem either. Merely subclassing NSTextStorage, doing nothing fancy, was causing the app to lag and crash, outputting the opaque message in the debugger “Terminated due to memory error”. Some folks online were helped by changing the internal store from a NSAttributedString to NSTextStorage, but for me the problem remained. The solution that did work for me? Write the subclass in Objective-C. At first I didn’t know why this worked, but looking into it further, I believe it comes down to the conversion between Swift’s String and Objective-C’s NSString. The two have basically the same interface, but to convert between the two is not a constant time operation. Apparently, the conversion is O(n), leading to performance problems with very large amounts to text. https://www.thecope.net/2019/09/15/resolving-slow-performance.html
gordonbrander
changed the title
Markup rendering is slow in big documents
Typing is slow in big documents
Jun 13, 2022
Ideally, we fix this through converting to TextKit2 in #214.
The document doesn't have to be that large. Just medium.
Learnings from troubleshooting:
textStorage
delegate does not improve perf. (Removes one parsing pass).Hypothesis:
Possible solutions:
The text was updated successfully, but these errors were encountered: