4

I'm attempting to create an editor in SwiftUI which can handle novel level word counts (50,000-100,000 words).

In the most bare bones example:

struct TextEditingView: View {
    @State private var fullText: String = "This is some editable text..."
    var body: some View {
        TextEditor(text: $fullText)
            .foregroundColor(Color.gray)
            .font(.custom("HelveticaNeue", size: 13))
            .lineSpacing(5)
    }
}

At around 3000-5000 words or so on an iPad + keyboard I experience huge amounts of latency, and stranger behaviors (like the view scrolling randomly). I experience similar things on macOS and iPhone.

I've tried to search for terms like Buffered TextEditor SwiftUI or TextEditor paging SwiftUI without much success.

It seems most implementations of text editors in swift can't really support this sort of document size, though Apple's notes seems to be able to handle it.

Can someone point me in the right direction?

Parth Mehrotra
  • 2,712
  • 1
  • 23
  • 31
  • With what kind of hardware? Just tried this same code with a 20,000,000 character string. It took about 20 seconds to load with 1GB ram but once the TextEditor appeared it worked very smoothly – JuJoDi Jan 12 '21 at 12:54
  • That's interesting is your string separated by spaces? On a Mac Pro, I'll generate 10,000 words of [lorem ipsum](https://www.lipsum.com/feed/html), paste it 3 times into the `TextEditor`, by the third paste I have unusable latency! – Parth Mehrotra Jan 12 '21 at 17:44
  • more data points: `NSTextView` doesn't suffer from the same latency – Parth Mehrotra Jan 12 '21 at 18:20
  • I just generated random text with this function https://stackoverflow.com/questions/26845307/generate-random-alphanumeric-string-in-swift I included spaces and it worked fine. When I paste huge blocks of lorem ipsum yes it's causing a problem. – JuJoDi Jan 12 '21 at 18:37
  • Could you try throwing some newlines in your test? Maybe this is a per-line sort of issue. – Parth Mehrotra Jan 12 '21 at 18:48
  • Also closely related: https://github.com/kyle-n/HighlightedTextEditor/issues/25 – Parth Mehrotra Jan 12 '21 at 18:49

0 Answers0