I have a TextArea control and I am storing the StyledText.RTFData into an SQLite database.
The RTFData is 15k - loading it from the database into the TextArea is pretty quick - no noticeable lag at all.
But saving the RTFData back to the database is taking 9 secs - an eternity when you are using an app.
I thought that maybe it was the database slowing it down… but if I take the database out of the equation and simply copy RTFData to a new string, it STILL takes 9 secs to make the copy.
Now, if I read the string from the database - into an actual String - and then copy that String, it is instantaneous.
So what is the deal with getting the RTFData ??? why is it taking so long ? Is there any advice on a different approach that might be quicker ?
Yes, definitely ! It is the call to RTFData that is taking so long… looking for any suggestions or advice on making that quicker… at least from the end user’s perspective.
I looked into using a Thread to do the save… but that is a no go since RTFData is buried in the UI.
RTFData has a long history of terrible performance in Xojo, and many of us users eventually gave up on it. Here’s one from 9 years ago which appears to have been closed w/o fixing? https://tracker.xojo.com/xojoinc/xojo/-/issues/33587
In the mean time, I am creating some functions to turn all of the styleruns into an array of strings… and then writing that to the database… the big question is whether it will be slower.
Var outString As String
Do Until EndedParsing()
outString = outString + GetFewParsedChars() // causes large releases + more allocs, thousand times
Loop
// Xojo performs better when you do
Var outArray() As String
Var outString As String
Do Until EndedParsing()
outArray.Add GetFewParsedChars() // allocs, thousand times
Loop
outString = String.FromArray(outArray, "") // fast alloc
outArray.RemoveAll() // fast release
My (limited) experience with RTFData and TextArea is that the slowness is only an issue under MacOS - it’s fine for me under Windows but unusably slow under MacOS. To me that would seem to point to TextArea rather than RTFData, but I haven’t looked deeply.
Both have a symbiotic relationship. And the problem arises from USING RTFData()
I was thinking that Xojo could be using an internal format and translating it. And as RTF is a Microsoft format invented in the 80’s and supported in the OS, I thought that Xojo was using system APIs to get it working ok in that platform and suffering to make the same for macOS.
But I was observing that in both Windows and macOS, there are “TextView” APIs, and both have the ability of getting RTF data out from the native component.
On Windows at least, putting styled text into a TextArea has always been excruciatingly slow. Pulling it back out is fast I would bet it’s the TextArea that has the problem, since it has to convert the RTF to styled text, which is slow even if you put the text in raw and then style it.