SwiftUI: Achieving Apple Notes App Smooth Text Editing Performance on iOS

I'm trying to build a high-performance text editor similar to the one found in the Apple Notes app.

To eliminate uncertainties, I've created a SwiftUI app from scratch and added only the TextEditor view, nothing else.

struct ContentView: View { @State private var text = ""

var body: some View {
    TextEditor(text: $text)
        .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
}

}

I've inserted a string with 347,023 characters, and text editing is very sluggish, slow, and text selection is even slower.

The same string in the Apple Notes app exhibits smooth text editing and selection.

I've also tried using UIKit with UITextView, but I'm experiencing the same performance drop.

How can I achieve the same level of smooth text editing and performance as the Apple Notes app?

I noticed that the following example is very smooth but you can't edit the text: https://developer.apple.com/documentation/uikit/textkit/using_textkit_2_to_interact_with_text

Could you provide a basic example to start with for creating a highly performant text editor on iOS?

Thank you.

SwiftUI: Achieving Apple Notes App Smooth Text Editing Performance on iOS
 
 
Q