XML and iOS is very slow

Hi.
Lots of elements to add to an XML document which I want to save in an iOS app.
It takes 8 seconds to save.
This is too slow.

What is the fastest way to append to a large string in a tight loop?
(I’ll build the XML by hand instead)
I assume

x = x + “new value”. would suffer the same way due to string reallocation?

do you have MBS plugins ?

I do

fill strings into an array and then do join() on the array.
That is quicker than appending to strings.

2 Likes

As @Christian_Schmitz suggests or maybe use: JoinStringMBS()
Then there is also an option to use a binarystream with memoryblock to append faster

Here is the last option in a bit more detail to speed up:
https://www.boredomsoft.org/string-building-in-realbasic.bs

I did intensive comparisons based on this link some time ago. Meanwhile, using Arrays is faster than composing Strings with MemoryBlocks. The Xojo framework has now optimized Arrays very neatly for speed.
Just use String Arrays and route the output String with String.FromArray.

2 Likes

If it’s so much faster maybe xojo could put a note about this in the docs @Paul_Lefebvre ?

1 Like

Xojo itself has a join function for strings.

Looks like it is now named String.FromArray

1 Like

I know…:wink:

Thanks all.
One of these will get me where I need to be.

1 Like

Update:
The difference between string concatenation and normal XML methods didnt make much difference in the end.

What did make a difference was threads, despite my reservations

I have a fast cloning routine internally that isnt the same as ‘save to file format’
(I use it as a form of undo)

Having cloned the current document, I make the clone save itself in a thread.
Then a list of available files needs to be updated: I can’t do that in a thread, so the thread sets a timer to run once and refresh a data set.
Much more responsive for the user.

2 Likes