SwiftUI TextEditor performance issues

Has anyone used the new SwiftUI 2.0 TextEditor with a sizeable string?

I'm currently trying it with a 400K text string and typing into the TextEditor horribly slow. Each letter I type takes seconds to appear.

When the text size is small (say just a few thousand characters) it's fast - so it's clearly something to do with performance. Is this a known issue? Should I be doing something to improve it?

PS - I do need to use it for my app (for e.g., a Markdown editor that loads a large file)

Code Block
 if let t = try? String(contentsOfFile: filePathName, encoding: .utf8) {
            editorText = t
            Config.logger.debug("EditorView.onAppear: Read text count = \(t.count) characters")
            }



That means that each time you type a character, there is some processing of the whole String. And probably the time grows linearly.

So if it takes 10 ms (unnoticeable) for a 1K string, it will take 4s for 400K String.

You should file a bug request, at least against doc to inform about it.

Note: 400K is more than a sizeable String…
Hi @Claude31 - yes, for my purposes I need to be able to load entire text files. It is supposed to be a "Text Editor" so I was hoping they had done basic performance tests against it. It certainly seems to be doing something wonky with every keystroke (I am not doing anything - haven't attached any listeners).

I will raise a bug, thank you. Hopefully they'll improve the text editor with more capabilities and better performance soon.

TextEditor is abysmally slow if the string being edited is part of a FileDocument's contents (actually TextField is pretty bad too). I guess it's actually saving the document per key stroke, or something equally lame.

This issue is simple: Bind the TextEditor to a String (@Binding) which is NOT a @State.

SwiftUI TextEditor performance issues
 
 
Q