Xojo is slower than Python

Welcome Dave !

1 Like

What are Xojo Framework methods written? Xojo or C or something else? I’ve written a number of replacement methods because the Xojo one lacks some characteristic and am interested to know whether that might slow my app down.

I think the framework is written in C++

Big chunks are written in C++ / Objective-C
And there are pieces written in Xojo itself
The split is hard for someone who doesnt know the internals to discern

the whole web framework is written in Xojo.
String handling in C++.
RegEx, XML and HTMLViewer is C++ in a plugin.
New Android stuff is mostly in Xojo.

Glad that the string handling is in C++. Text was very slow for me, meaning that to get reasonable speed, I had to resort to tricks like splitting the text into arrays. Anyway, only using Strings now.

Text is also in C++ (Windows & Linux) & Objective-C (macOS)

The biggest issue with text was that unlike string it deal in code points and grapheme clusters (what amounts to user perceived characters)

How is Text stored internally? If I had two Text strings to concatenate, I found it much faster to split each into character arrays, and then use array methods to add one to the other, then join to convert back to a Text.

Again, to replace a Text in the middle of a Text with another Text, I did the same thing (PHP provides a method to do this). Made me wonder why they didn’t implement a Text as an array of characters.

Also: if I have:

Var  s as String, m as MemoryBlock

s = m
m = s

Does each of these involve copying the data? It ought not to.

Text is, from what I recall, stored as runs of code points
The ICU library on Windows & Linux could be examined to see for sure
On macOS it uses a native NSString which I dont know the internals of
Concatenation character by charcter should be slower than one single concatenation BUT that may depend on the library used
The reason I say this is that a single concatenation creates a new string with enough space foe the two originals
Character by character it does that every time and does a LOT more allocations

BUT this will depend on platform - on macOS NSString is pretty darned fast
On Windows & Linux this is not quite as fast and so you could see big differences between platforms

I’m pretty sure it will. Why ? Because without knowing all code that might mutate s or m, everywhere (if if s or ma re properties etc) if you do not copy them then code like the following becomes really problematic

if s is not copied then changes to m are reflected in s which is NOT expected

Data flow analysis could tell you if you need to copy right away or can defer it until there is a mutation but I do not know that Xojo’s compiler does this. That would make compilations a lot slower I believe

I’m not doing concatenation of single characters - see this method:

sub substr_replace (inpstr() As string, repstr() As string, startind As Integer, dellen As Integer) as string()

// Takes the inpstr array, excises dellen chars starting at startind, and inserts
// repstr in its place. Allows repstr to be Nil, in which case nothing is inserted.

Var  i, st, lim As Integer, retstr() As String

if  (repstr is Nil)  then
  Var  empty() As String
  repstr = empty
end if

lim = startind - 1

for i=0 to lim
  retstr.AddRow (inpstr(i))
Next

lim = repstr.LastRowIndex

for i=0 to lim
  retstr.AddRow (repstr(i))
next

st  = startind + dellen
lim = inpstr.LastRowIndex

for i = st to lim
  retstr.AddRow (inpstr(i))
Next

return retstr

end sub

OK I take the point about s&m :upside_down_face:

ah just the way you’d written it thats what it sounded like

but I see your using arrays of strings - which are not texts but they are also immutable as I described

Yes, I am now. When I started I tried to be a good boy and use Text everywhere. But I found some things to be slow - like sometimes reading a block of base64 encoded lines of Text from a socket. There might be 400k lines to read. Each one to be compared with a termination line, and then appended to a block of Text I was building up. Originally written in PHP, this was not taking very long (some seconds) but expanded to a couple of minutes using Text in Xojo. Being done in a thread but even then tending to block the UI.

I’ve modified a lot since those early days, including going to String everywhere and saving the lines as an array of Strings and joining them later, rather than as I went along. All these changes have largely eliminated those sorts of problems.

I did find the whole conversion of what was, I suppose, in fact a webapp originally written in PHP/JavaScript, to Xojo, to have been quite tough. I kept expecting that there’d be some show-stopper, some facet of the business that in Xojo was simply missing, that would prevent me getting there, but I think I’ve eventually got there.